make-mp-data 2.0.19 → 2.0.21
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/dungeons/big.js +7 -6
- package/dungeons/business.js +21 -3
- package/dungeons/experiments.js +8 -7
- package/dungeons/media.js +7 -7
- package/dungeons/sanity.js +8 -14
- package/dungeons/simple.js +1 -0
- package/dungeons/student-teacher.js +475 -0
- package/dungeons/userAgent.js +7 -7
- package/entry.js +13 -2
- package/index.js +74 -3
- package/lib/core/config-validator.js +22 -7
- package/lib/core/context.js +31 -16
- package/lib/core/storage.js +20 -19
- package/lib/generators/events.js +41 -18
- package/lib/orchestrators/worker-manager.js +5 -2
- package/lib/templates/abbreviated.d.ts +158 -0
- package/lib/{data → templates}/defaults.js +2 -2
- package/lib/templates/dungeon-template.js +110 -0
- package/lib/templates/instructions.txt +77 -0
- package/lib/templates/verbose-schema.js +311 -0
- package/lib/utils/ai.js +42 -64
- package/lib/utils/chart.js +5 -0
- package/lib/utils/utils.js +69 -45
- package/package.json +10 -11
- package/types.d.ts +134 -126
- package/lib/cloud-function.js +0 -20
- /package/lib/{utils/prompt.txt → templates/prompt (old).txt} +0 -0
package/types.d.ts
CHANGED
|
@@ -1,18 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
export interface Dungeon {
|
|
1
|
+
/**
|
|
2
|
+
* most of the time, the value of a property is a primitive
|
|
3
|
+
*/
|
|
4
|
+
type Primitives = string | number | boolean | Date | Record<string, any>;
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* a "validValue" can be a primitive, an array of primitives, or a function that returns a primitive
|
|
8
|
+
*/
|
|
9
|
+
export type ValueValid = Primitives | ValueValid[] | (() => ValueValid);
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* main config object for the entire data generation
|
|
13
|
+
*/
|
|
14
|
+
export interface Dungeon {
|
|
16
15
|
// constants
|
|
17
16
|
token?: string;
|
|
18
17
|
seed?: string;
|
|
@@ -71,34 +70,34 @@ declare namespace main {
|
|
|
71
70
|
|
|
72
71
|
//probabilities
|
|
73
72
|
percentUsersBornInDataset?: number;
|
|
74
|
-
|
|
73
|
+
}
|
|
75
74
|
|
|
76
|
-
|
|
75
|
+
export type SCDProp = {
|
|
77
76
|
type?: string | "user" | "company_id" | "team_id" | "department_id";
|
|
78
77
|
frequency: "day" | "week" | "month" | "year";
|
|
79
78
|
values: ValueValid;
|
|
80
79
|
timing: "fixed" | "fuzzy";
|
|
81
80
|
max?: number;
|
|
82
|
-
|
|
81
|
+
};
|
|
83
82
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
83
|
+
/**
|
|
84
|
+
* the soup is a set of parameters that determine the distribution of events over time
|
|
85
|
+
*/
|
|
86
|
+
type soup = {
|
|
88
87
|
deviation?: number;
|
|
89
88
|
peaks?: number;
|
|
90
89
|
mean?: number;
|
|
91
|
-
|
|
90
|
+
};
|
|
92
91
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
92
|
+
/**
|
|
93
|
+
* the types of hooks that can be used
|
|
94
|
+
*/
|
|
95
|
+
export type hookTypes =
|
|
97
96
|
| "event"
|
|
98
97
|
| "user"
|
|
99
98
|
| "group"
|
|
100
99
|
| "lookup"
|
|
101
|
-
| "scd"
|
|
100
|
+
// | "scd"
|
|
102
101
|
| "scd-pre"
|
|
103
102
|
| "mirror"
|
|
104
103
|
| "funnel-pre"
|
|
@@ -109,32 +108,33 @@ declare namespace main {
|
|
|
109
108
|
| "everything"
|
|
110
109
|
| "";
|
|
111
110
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
111
|
+
/**
|
|
112
|
+
* a hook is a function that can be called before each entity is created, and can be used to modify attributes
|
|
113
|
+
*/
|
|
114
|
+
export type Hook<T> = (record: any, type: hookTypes, meta: any) => T;
|
|
116
115
|
|
|
117
|
-
|
|
116
|
+
export interface hookArrayOptions<T> {
|
|
118
117
|
hook?: Hook<T>;
|
|
119
118
|
type?: hookTypes;
|
|
120
119
|
filename?: string;
|
|
121
120
|
format?: "csv" | "json" | string;
|
|
122
121
|
concurrency?: number;
|
|
122
|
+
context?: Context;
|
|
123
123
|
[key: string]: any;
|
|
124
|
-
|
|
124
|
+
}
|
|
125
125
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
hookPush: (item: T | T[], ...meta) => any;
|
|
126
|
+
/**
|
|
127
|
+
* an enriched array is an array that has a hookPush method that can be used to transform-then-push items into the array
|
|
128
|
+
*/
|
|
129
|
+
export interface HookedArray<T> extends Array<T> {
|
|
130
|
+
hookPush: (item: T | T[], ...meta: any[]) => any;
|
|
131
131
|
flush: () => void;
|
|
132
132
|
getWriteDir: () => string;
|
|
133
133
|
getWritePath: () => string;
|
|
134
134
|
[key: string]: any;
|
|
135
|
-
|
|
135
|
+
}
|
|
136
136
|
|
|
137
|
-
|
|
137
|
+
export type AllData =
|
|
138
138
|
| HookedArray<EventSchema>
|
|
139
139
|
| HookedArray<UserProfile>
|
|
140
140
|
| HookedArray<GroupProfileSchema>
|
|
@@ -142,10 +142,10 @@ declare namespace main {
|
|
|
142
142
|
| HookedArray<SCDSchema>
|
|
143
143
|
| any[];
|
|
144
144
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
145
|
+
/**
|
|
146
|
+
* the storage object is a key-value store that holds arrays of data
|
|
147
|
+
*/
|
|
148
|
+
export interface Storage {
|
|
149
149
|
eventData?: HookedArray<EventSchema>;
|
|
150
150
|
mirrorEventData?: HookedArray<EventSchema>;
|
|
151
151
|
userProfilesData?: HookedArray<UserProfile>;
|
|
@@ -154,24 +154,24 @@ declare namespace main {
|
|
|
154
154
|
lookupTableData?: HookedArray<LookupTableSchema>[];
|
|
155
155
|
scdTableData?: HookedArray<SCDSchema>[];
|
|
156
156
|
groupEventData?: HookedArray<EventSchema>;
|
|
157
|
-
|
|
157
|
+
}
|
|
158
158
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
159
|
+
/**
|
|
160
|
+
* Runtime state for tracking execution metrics and flags
|
|
161
|
+
*/
|
|
162
|
+
export interface RuntimeState {
|
|
163
163
|
operations: number;
|
|
164
164
|
eventCount: number;
|
|
165
165
|
userCount: number;
|
|
166
166
|
isBatchMode: boolean;
|
|
167
167
|
verbose: boolean;
|
|
168
168
|
isCLI: boolean;
|
|
169
|
-
|
|
169
|
+
}
|
|
170
170
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
171
|
+
/**
|
|
172
|
+
* Default data factories for generating realistic test data
|
|
173
|
+
*/
|
|
174
|
+
export interface Defaults {
|
|
175
175
|
locationsUsers: () => any[];
|
|
176
176
|
locationsEvents: () => any[];
|
|
177
177
|
iOSDevices: () => any[];
|
|
@@ -179,13 +179,13 @@ declare namespace main {
|
|
|
179
179
|
desktopDevices: () => any[];
|
|
180
180
|
browsers: () => any[];
|
|
181
181
|
campaigns: () => any[];
|
|
182
|
-
|
|
182
|
+
}
|
|
183
183
|
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
184
|
+
/**
|
|
185
|
+
* Context object that replaces global variables with dependency injection
|
|
186
|
+
* Contains validated config, storage containers, defaults, and runtime state
|
|
187
|
+
*/
|
|
188
|
+
export interface Context {
|
|
189
189
|
config: Dungeon;
|
|
190
190
|
storage: Storage | null;
|
|
191
191
|
defaults: Defaults;
|
|
@@ -193,6 +193,7 @@ declare namespace main {
|
|
|
193
193
|
runtime: RuntimeState;
|
|
194
194
|
FIXED_NOW: number;
|
|
195
195
|
FIXED_BEGIN?: number;
|
|
196
|
+
TIME_SHIFT_SECONDS: number;
|
|
196
197
|
|
|
197
198
|
// State update methods
|
|
198
199
|
incrementOperations(): void;
|
|
@@ -212,12 +213,12 @@ declare namespace main {
|
|
|
212
213
|
// Time helper methods
|
|
213
214
|
getTimeShift(): number;
|
|
214
215
|
getDaysShift(): number;
|
|
215
|
-
|
|
216
|
+
}
|
|
216
217
|
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
218
|
+
/**
|
|
219
|
+
* how we define events and their properties
|
|
220
|
+
*/
|
|
221
|
+
export interface EventConfig {
|
|
221
222
|
event?: string;
|
|
222
223
|
weight?: number;
|
|
223
224
|
properties?: Record<string, ValueValid>;
|
|
@@ -225,19 +226,19 @@ declare namespace main {
|
|
|
225
226
|
isChurnEvent?: boolean;
|
|
226
227
|
isSessionStartEvent?: boolean;
|
|
227
228
|
relativeTimeMs?: number;
|
|
228
|
-
|
|
229
|
+
}
|
|
229
230
|
|
|
230
|
-
|
|
231
|
+
export interface GroupEventConfig extends EventConfig {
|
|
231
232
|
frequency: number; //how often the event occurs (in days)
|
|
232
233
|
group_key: string; //the key that the group is based on
|
|
233
234
|
attribute_to_user: boolean; //if true, the event also goes to a user
|
|
234
235
|
group_size: number; //the number of users in the group
|
|
235
|
-
|
|
236
|
+
}
|
|
236
237
|
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
238
|
+
/**
|
|
239
|
+
* the generated event data
|
|
240
|
+
*/
|
|
241
|
+
export interface EventSchema {
|
|
241
242
|
event: string;
|
|
242
243
|
time: string;
|
|
243
244
|
source: string;
|
|
@@ -246,12 +247,20 @@ declare namespace main {
|
|
|
246
247
|
session_id?: string;
|
|
247
248
|
user_id?: string;
|
|
248
249
|
[key: string]: ValueValid;
|
|
249
|
-
|
|
250
|
+
}
|
|
250
251
|
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
252
|
+
/**
|
|
253
|
+
* how we define funnels and their properties
|
|
254
|
+
*/
|
|
255
|
+
export interface Funnel {
|
|
256
|
+
/**
|
|
257
|
+
* the name of the funnel
|
|
258
|
+
*/
|
|
259
|
+
name?: string;
|
|
260
|
+
/**
|
|
261
|
+
* the description of the funnel
|
|
262
|
+
*/
|
|
263
|
+
description?: string;
|
|
255
264
|
/**
|
|
256
265
|
* the sequence of events that define the funnel
|
|
257
266
|
*/
|
|
@@ -274,14 +283,14 @@ declare namespace main {
|
|
|
274
283
|
* how the events in the funnel are ordered for each user
|
|
275
284
|
*/
|
|
276
285
|
order?:
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
286
|
+
| "sequential"
|
|
287
|
+
| "first-fixed"
|
|
288
|
+
| "last-fixed"
|
|
289
|
+
| "random" //totally shuffled
|
|
290
|
+
| "first-and-last-fixed"
|
|
291
|
+
| "middle-fixed"
|
|
292
|
+
| "interrupted"
|
|
293
|
+
| string;
|
|
285
294
|
|
|
286
295
|
/**
|
|
287
296
|
* todo: implement this
|
|
@@ -302,13 +311,13 @@ declare namespace main {
|
|
|
302
311
|
* funnel properties go onto each event in the funnel and are held constant
|
|
303
312
|
*/
|
|
304
313
|
props?: Record<string, ValueValid>;
|
|
305
|
-
|
|
314
|
+
}
|
|
306
315
|
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
316
|
+
/**
|
|
317
|
+
* mirror props are used to show mutations of event data over time
|
|
318
|
+
* there are different strategies for how to mutate the data
|
|
319
|
+
*/
|
|
320
|
+
export interface MirrorProps {
|
|
312
321
|
/**
|
|
313
322
|
* the event that will be mutated in the new version
|
|
314
323
|
*/
|
|
@@ -325,18 +334,18 @@ declare namespace main {
|
|
|
325
334
|
* optional: for 'fill' mode, daysUnfilled will dictate where the cutoff is in the unfilled data
|
|
326
335
|
*/
|
|
327
336
|
daysUnfilled?: number;
|
|
328
|
-
|
|
337
|
+
}
|
|
329
338
|
|
|
330
|
-
|
|
339
|
+
export interface UserProfile {
|
|
331
340
|
name?: string;
|
|
332
341
|
email?: string;
|
|
333
342
|
avatar?: string;
|
|
334
343
|
created: string | undefined;
|
|
335
344
|
distinct_id: string;
|
|
336
345
|
[key: string]: ValueValid;
|
|
337
|
-
|
|
346
|
+
}
|
|
338
347
|
|
|
339
|
-
|
|
348
|
+
export interface Person {
|
|
340
349
|
name: string;
|
|
341
350
|
email?: string;
|
|
342
351
|
avatar?: string;
|
|
@@ -344,48 +353,48 @@ declare namespace main {
|
|
|
344
353
|
anonymousIds: string[];
|
|
345
354
|
sessionIds: string[];
|
|
346
355
|
distinct_id?: string;
|
|
347
|
-
|
|
356
|
+
}
|
|
348
357
|
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
358
|
+
/**
|
|
359
|
+
* the generated user data
|
|
360
|
+
*/
|
|
361
|
+
export interface LookupTableSchema {
|
|
353
362
|
key: string;
|
|
354
363
|
entries: number;
|
|
355
364
|
attributes: Record<string, ValueValid>;
|
|
356
|
-
|
|
365
|
+
}
|
|
357
366
|
|
|
358
|
-
|
|
367
|
+
export interface LookupTableData {
|
|
359
368
|
key: string;
|
|
360
369
|
data: any[];
|
|
361
|
-
|
|
370
|
+
}
|
|
362
371
|
|
|
363
|
-
|
|
372
|
+
export interface SCDSchema {
|
|
364
373
|
distinct_id: string;
|
|
365
374
|
insertTime: string;
|
|
366
375
|
startTime: string;
|
|
367
376
|
[key: string]: ValueValid;
|
|
368
|
-
|
|
377
|
+
}
|
|
369
378
|
|
|
370
|
-
|
|
379
|
+
export interface GroupProfileSchema {
|
|
371
380
|
key: string;
|
|
372
381
|
data: any[];
|
|
373
|
-
|
|
382
|
+
}
|
|
374
383
|
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
384
|
+
/**
|
|
385
|
+
* the end result of importing data into mixpanel
|
|
386
|
+
*/
|
|
387
|
+
export interface ImportResults {
|
|
379
388
|
events: ImportResult;
|
|
380
389
|
users: ImportResult;
|
|
381
390
|
groups: ImportResult[];
|
|
382
|
-
|
|
383
|
-
|
|
391
|
+
}
|
|
392
|
+
type ImportResult = import("mixpanel-import").ImportResults;
|
|
384
393
|
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
394
|
+
/**
|
|
395
|
+
* the end result of the data generation
|
|
396
|
+
*/
|
|
397
|
+
export type Result = {
|
|
389
398
|
eventData: EventSchema[];
|
|
390
399
|
mirrorEventData: EventSchema[];
|
|
391
400
|
userProfilesData: any[];
|
|
@@ -396,16 +405,15 @@ declare namespace main {
|
|
|
396
405
|
importResults?: ImportResults;
|
|
397
406
|
files?: string[];
|
|
398
407
|
time?: {
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
408
|
+
start: number;
|
|
409
|
+
end: number;
|
|
410
|
+
delta: number;
|
|
411
|
+
human: string;
|
|
403
412
|
};
|
|
404
413
|
operations?: number;
|
|
405
414
|
eventCount?: number;
|
|
406
415
|
userCount?: number;
|
|
407
|
-
|
|
408
|
-
}
|
|
416
|
+
};
|
|
409
417
|
|
|
410
418
|
/**
|
|
411
419
|
* Mixpanel Data Generator
|
|
@@ -414,6 +422,6 @@ declare namespace main {
|
|
|
414
422
|
* import datagenerator from 'make-mp-data';
|
|
415
423
|
* const data = await datagenerator({...opts});
|
|
416
424
|
*/
|
|
417
|
-
declare function main(config:
|
|
425
|
+
declare function main(config: Dungeon): Promise<Result>;
|
|
418
426
|
|
|
419
|
-
export
|
|
427
|
+
export default main;
|
package/lib/cloud-function.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Cloud Function Entry Point
|
|
3
|
-
* Provides a clean interface for Google Cloud Functions deployment
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
/** @typedef {import('../types').Dungeon} Config */
|
|
7
|
-
|
|
8
|
-
import functions from '@google-cloud/functions-framework';
|
|
9
|
-
import { handleCloudFunctionEntry } from './orchestrators/worker-manager.js';
|
|
10
|
-
import main from '../index.js';
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Cloud Function HTTP entry point
|
|
14
|
-
* Handles distributed data generation across multiple workers
|
|
15
|
-
*/
|
|
16
|
-
functions.http('entry', async (req, res) => {
|
|
17
|
-
await handleCloudFunctionEntry(req, res, main);
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
export { handleCloudFunctionEntry, main };
|
|
File without changes
|