@shaxpir/duiduidui-models 1.3.1 → 1.3.3
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/dist/index.d.ts +1 -0
- package/dist/index.js +2 -0
- package/package.json +5 -1
- package/lib/index.ts +0 -7
- package/lib/models/ArrayView.ts +0 -203
- package/lib/models/BayesianScore.ts +0 -32
- package/lib/models/ChangeModel.ts +0 -94
- package/lib/models/Content.ts +0 -107
- package/lib/models/ContentKind.ts +0 -19
- package/lib/models/Device.ts +0 -90
- package/lib/models/GeoLocation.ts +0 -4
- package/lib/models/Hanzi.ts +0 -16
- package/lib/models/Manifest.ts +0 -171
- package/lib/models/Media.ts +0 -125
- package/lib/models/Metric.ts +0 -233
- package/lib/models/Model.ts +0 -325
- package/lib/models/Operation.ts +0 -205
- package/lib/models/Permissions.ts +0 -19
- package/lib/models/Phrase.ts +0 -53
- package/lib/models/Profile.ts +0 -117
- package/lib/models/Progress.ts +0 -101
- package/lib/models/Review.ts +0 -18
- package/lib/models/Session.ts +0 -149
- package/lib/models/Term.ts +0 -202
- package/lib/models/User.ts +0 -97
- package/lib/models/Workspace.ts +0 -129
- package/lib/models/index.ts +0 -24
- package/lib/repo/ConnectionListener.ts +0 -25
- package/lib/repo/PermissiveJson1.ts +0 -14
- package/lib/repo/ShareSync.ts +0 -383
- package/lib/repo/TextEditOps.ts +0 -50
- package/lib/repo/index.ts +0 -6
- package/lib/util/Encryption.ts +0 -5
- package/lib/util/Logging.ts +0 -568
- package/lib/util/index.ts +0 -4
- package/tsconfig.json +0 -25
- package/tslint.json +0 -46
package/lib/util/Logging.ts
DELETED
|
@@ -1,568 +0,0 @@
|
|
|
1
|
-
export type LogLevel = 'error' | 'warn' | 'info' | 'debug';
|
|
2
|
-
|
|
3
|
-
export type ClientType = 'user' | 'server' | 'desktop' | 'browser';
|
|
4
|
-
|
|
5
|
-
export interface LogItem {
|
|
6
|
-
timestamp: string;
|
|
7
|
-
level: LogLevel;
|
|
8
|
-
message: string;
|
|
9
|
-
fields: LogFields;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
// The LogRecorder interface is used to define the interface for the transport mechanism that
|
|
13
|
-
// actually records the log entries somewhere. It must provice a recordLogEntry method that takes
|
|
14
|
-
// a LogItem object as an argument, and it must provide an inspect method that takes an error object
|
|
15
|
-
// as an argument and returns a string representation of the error. This allows the Logger class to
|
|
16
|
-
// record log entries without knowing the details of how they are recorded. And the 'inspect' method
|
|
17
|
-
// will have a different implementation in the browser than in node.js.
|
|
18
|
-
export interface LogRecorder {
|
|
19
|
-
recordLogEntry(item: LogItem): void;
|
|
20
|
-
inspect(err:any):string;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export abstract class ConsoleJsonLogRecorder implements LogRecorder {
|
|
24
|
-
abstract inspect(err: any): string;
|
|
25
|
-
public recordLogEntry(item: LogItem): void {
|
|
26
|
-
const stringified = JSON.stringify(item);
|
|
27
|
-
if (item.level === 'error') {
|
|
28
|
-
console.error(stringified);
|
|
29
|
-
} else if (item.level === 'warn') {
|
|
30
|
-
console.warn(stringified);
|
|
31
|
-
} else {
|
|
32
|
-
console.log(stringified);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export class Logger {
|
|
38
|
-
|
|
39
|
-
private recorder:LogRecorder;
|
|
40
|
-
|
|
41
|
-
private timestamp:string;
|
|
42
|
-
private level:LogLevel;
|
|
43
|
-
private message:string;
|
|
44
|
-
private fields:LogFields = {};
|
|
45
|
-
|
|
46
|
-
constructor(recorder:LogRecorder) {
|
|
47
|
-
this.recorder = recorder;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/* static method for creating a new Logger instance, optionally with a context */
|
|
51
|
-
|
|
52
|
-
public static create(
|
|
53
|
-
recorder:LogRecorder,
|
|
54
|
-
context?:string,
|
|
55
|
-
):Logger {
|
|
56
|
-
const b = new Logger(recorder);
|
|
57
|
-
if (context) {
|
|
58
|
-
b.withContext(context);
|
|
59
|
-
}
|
|
60
|
-
return b;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/* method for cloning a Logger instance */
|
|
64
|
-
|
|
65
|
-
public clone():Logger {
|
|
66
|
-
const clone = new Logger(this.recorder);
|
|
67
|
-
clone.withTimestamp(this.timestamp);
|
|
68
|
-
clone.withLevel(this.level);
|
|
69
|
-
clone.withMessage(this.message);
|
|
70
|
-
clone.withFields(this.fields);
|
|
71
|
-
return clone;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/* method for sending a log entry, which must be called in order to record the log item */
|
|
75
|
-
|
|
76
|
-
public send():void {
|
|
77
|
-
let timestamp = this.timestamp;
|
|
78
|
-
if (!timestamp) {
|
|
79
|
-
timestamp = new Date().toISOString();
|
|
80
|
-
}
|
|
81
|
-
this.recorder.recordLogEntry({
|
|
82
|
-
timestamp: timestamp,
|
|
83
|
-
level: this.level,
|
|
84
|
-
message: this.message,
|
|
85
|
-
fields: this.fields
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
/* method for setting a level and message */
|
|
90
|
-
|
|
91
|
-
public info(message:string):Logger {
|
|
92
|
-
this.withLevel('info');
|
|
93
|
-
this.withMessage(message);
|
|
94
|
-
return this;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
public warn(message:string):Logger {
|
|
98
|
-
this.withLevel('warn');
|
|
99
|
-
this.withMessage(message);
|
|
100
|
-
return this;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
public debug(message:string):Logger {
|
|
104
|
-
this.withLevel('debug');
|
|
105
|
-
this.withMessage(message);
|
|
106
|
-
return this;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
public error(message:string, err?:any):Logger {
|
|
110
|
-
this.withLevel('error');
|
|
111
|
-
this.withMessage(message);
|
|
112
|
-
this.withError(err);
|
|
113
|
-
return this;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
/* methods for setting intrinsic LogItem properties */
|
|
117
|
-
|
|
118
|
-
public withTimestamp(timestamp:Date|string):Logger {
|
|
119
|
-
if (timestamp instanceof Date) {
|
|
120
|
-
this.timestamp = timestamp.toISOString();
|
|
121
|
-
} else {
|
|
122
|
-
this.timestamp = timestamp;
|
|
123
|
-
}
|
|
124
|
-
return this;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
public withLevel(level:LogLevel):Logger {
|
|
128
|
-
this.level = level;
|
|
129
|
-
return this;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
public withMessage(message:string):Logger {
|
|
133
|
-
this.message = message;
|
|
134
|
-
return this;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
public withFields(fields:LogFields):Logger {
|
|
138
|
-
// Iterate over all the new fields, and enforce the field types. Add them
|
|
139
|
-
// one-by-one using the withField method, which will enforce the field types.
|
|
140
|
-
let keys = Object.keys(fields);
|
|
141
|
-
for (let i = 0; i < keys.length; i++) {
|
|
142
|
-
let key = keys[i];
|
|
143
|
-
let value = fields[key];
|
|
144
|
-
this.withField(key, value);
|
|
145
|
-
}
|
|
146
|
-
return this;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
public withField(key:string, value:string | number | boolean | Date):Logger {
|
|
150
|
-
Logger.enforceFieldType(key, value);
|
|
151
|
-
if (value instanceof Date) {
|
|
152
|
-
value = value.toISOString();
|
|
153
|
-
}
|
|
154
|
-
this.fields[key] = value;
|
|
155
|
-
return this;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
/* methods for setting specific fields, using appropriate types */
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
public withServiceName(serviceName:string):Logger {
|
|
162
|
-
this.withField('service_name', serviceName);
|
|
163
|
-
return this;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
public withNodeName(nodeName:string):Logger {
|
|
167
|
-
this.withField('node_name', nodeName);
|
|
168
|
-
return this;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
public withVersion(version:string):Logger {
|
|
172
|
-
this.withField('version', version);
|
|
173
|
-
return this;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
public withClientType(clientType:ClientType):Logger {
|
|
177
|
-
this.withField('client_type', clientType);
|
|
178
|
-
return this;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
public withClientServiceName(serviceName:string):Logger {
|
|
182
|
-
this.withField('client_service_name', serviceName);
|
|
183
|
-
return this;
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
public withClientNodeName(nodeName:string):Logger {
|
|
187
|
-
this.withField('client_node_name', nodeName);
|
|
188
|
-
return this;
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
public withClientVersion(version:string):Logger {
|
|
192
|
-
this.withField('client_version', version);
|
|
193
|
-
return this;
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
public withTopic(topic:string):Logger {
|
|
197
|
-
this.withField('topic', topic);
|
|
198
|
-
return this;
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
public withSubtopic(subtopic:string):Logger {
|
|
202
|
-
this.withField('subtopic', subtopic);
|
|
203
|
-
return this;
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
public withName(name:string):Logger {
|
|
207
|
-
this.withField('name', name);
|
|
208
|
-
return this;
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
public withContext(context:string):Logger {
|
|
212
|
-
this.withField('context', context);
|
|
213
|
-
return this;
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
public withUsingJwt(usingJwt:boolean):Logger {
|
|
217
|
-
this.withField('using_jwt', usingJwt);
|
|
218
|
-
return this;
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
public withUsingPassHash(usingPassHash:boolean):Logger {
|
|
222
|
-
this.withField('using_pass_hash', usingPassHash);
|
|
223
|
-
return this;
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
public withUserId(userId:string):Logger {
|
|
227
|
-
this.withField('user_id', userId);
|
|
228
|
-
return this;
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
public withEmail(email:string):Logger {
|
|
232
|
-
this.withField('email', email);
|
|
233
|
-
return this;
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
public withUrl(url:string):Logger {
|
|
237
|
-
this.withField('url', url);
|
|
238
|
-
return this;
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
public withSessionRef(sessionRef:string):Logger {
|
|
242
|
-
this.withField('session_ref', sessionRef);
|
|
243
|
-
return this;
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
public withContentKind(kind:string):Logger {
|
|
247
|
-
this.withField('content_kind', kind);
|
|
248
|
-
return this;
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
public withContentRef(ref:string):Logger {
|
|
252
|
-
this.withField('content_ref', ref);
|
|
253
|
-
return this;
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
public withCount(count:number):Logger {
|
|
257
|
-
this.withField('count', count);
|
|
258
|
-
return this;
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
public withDurationMillis(duration:number):Logger {
|
|
262
|
-
this.withField('duration_millis', duration);
|
|
263
|
-
return this;
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
public withDocVersion(version:number):Logger {
|
|
267
|
-
this.withField('doc_version', version);
|
|
268
|
-
return this;
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
public withWordCount(count:number):Logger {
|
|
272
|
-
this.withField('word_count', count);
|
|
273
|
-
return this;
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
public withBucket(bucket:string):Logger {
|
|
277
|
-
this.withField('bucket', bucket);
|
|
278
|
-
return this;
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
public withFileName(fileName:string):Logger {
|
|
282
|
-
this.withField('file_name', fileName);
|
|
283
|
-
return this;
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
public withFileSize(size:number):Logger {
|
|
287
|
-
this.withField('file_size', size);
|
|
288
|
-
return this;
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
public withRequestBody(body:any):Logger {
|
|
292
|
-
this.withField('request_body', Logger.ensureStringified(body));
|
|
293
|
-
return this;
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
public clearParams():Logger {
|
|
297
|
-
delete this.fields.params;
|
|
298
|
-
return this;
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
public withParams(params:any):Logger {
|
|
302
|
-
// Layer in the new params over the old params, if they exist.
|
|
303
|
-
const oldParams = this.fields.params;
|
|
304
|
-
if (oldParams) {
|
|
305
|
-
let oldParamsObj:any;
|
|
306
|
-
try {
|
|
307
|
-
oldParamsObj = JSON.parse(oldParams);
|
|
308
|
-
} catch (e) {
|
|
309
|
-
oldParamsObj = {};
|
|
310
|
-
}
|
|
311
|
-
this.fields.params = JSON.stringify({ ...oldParamsObj, ...params });
|
|
312
|
-
} else {
|
|
313
|
-
this.fields.params = JSON.stringify(params);
|
|
314
|
-
}
|
|
315
|
-
return this;
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
public withChangingData(originalData:any, transformedData:any):Logger {
|
|
319
|
-
this.withOriginalData(originalData);
|
|
320
|
-
this.withTransformedData(transformedData);
|
|
321
|
-
return this;
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
public withOriginalData(data:any):Logger {
|
|
325
|
-
this.withField('original_data', Logger.ensureStringified(data));
|
|
326
|
-
return this;
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
public withTransformedData(data:any):Logger {
|
|
330
|
-
this.withField('transformed_data', Logger.ensureStringified(data));
|
|
331
|
-
return this;
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
public withIgnoreConflict(ignoreConflict:boolean):Logger {
|
|
335
|
-
this.withField('ignore_conflict', ignoreConflict);
|
|
336
|
-
return this;
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
public withError(err:any):Logger {
|
|
340
|
-
let stringified:string;
|
|
341
|
-
if (err != null && err != undefined) {
|
|
342
|
-
if (typeof err === 'string') {
|
|
343
|
-
stringified = err;
|
|
344
|
-
} else if (err instanceof Error) {
|
|
345
|
-
// If this is a structured error object, it might have circular references, so handle that
|
|
346
|
-
// with the 'inspect' function. First, attempt to use a normal JSON.stringify() operation,
|
|
347
|
-
// and if that fails, (probably because of circular refs) then fall back to using 'inspect'.
|
|
348
|
-
try {
|
|
349
|
-
stringified = JSON.stringify(err);
|
|
350
|
-
if (stringified === '{}') {
|
|
351
|
-
stringified = this.recorder.inspect(err);
|
|
352
|
-
}
|
|
353
|
-
} catch (e) {
|
|
354
|
-
stringified = this.recorder.inspect(err);
|
|
355
|
-
}
|
|
356
|
-
} else {
|
|
357
|
-
stringified = JSON.stringify(err);
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
if (stringified) {
|
|
361
|
-
this.withField('error_body', stringified);
|
|
362
|
-
}
|
|
363
|
-
return this;
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
private static ensureStringified(value:any):string {
|
|
367
|
-
if (typeof value === 'string') {
|
|
368
|
-
return value;
|
|
369
|
-
} else {
|
|
370
|
-
return JSON.stringify(value);
|
|
371
|
-
}
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
private static enforceFieldType(key:string, value:any):void {
|
|
375
|
-
// Users can pass in Date values for fields that end with '_time' or '_date'. Those will be recorded
|
|
376
|
-
// as strings in the log entry, but we need to enforce that the field keys end with '_time' or '_date'.
|
|
377
|
-
// Likewise, if fields end with these suffixes, we need to enforce that the values either be strings
|
|
378
|
-
// that can be parsed as Dates, or actual Date objects (which will be stringified in the withField method).
|
|
379
|
-
if (value instanceof Date) {
|
|
380
|
-
if (key.endsWith('_time') || key.endsWith('_date')) {
|
|
381
|
-
return;
|
|
382
|
-
} else {
|
|
383
|
-
throw new Error(`date field keys must end with '_time' or '_date': ${key}`);
|
|
384
|
-
}
|
|
385
|
-
} else if (key.endsWith('_time') || key.endsWith('_date')) {
|
|
386
|
-
// Enforce that fields ending with '_time' or '_date' are strings or Dates.
|
|
387
|
-
if (typeof value == 'string') {
|
|
388
|
-
// Validate that the string value used for this field is parseable as a Date.
|
|
389
|
-
let date = new Date(value);
|
|
390
|
-
if (isNaN(date.getTime())) {
|
|
391
|
-
throw new Error(`invalid date for log field '${key}': ${value}`);
|
|
392
|
-
}
|
|
393
|
-
} else {
|
|
394
|
-
throw new Error(Logger.makeTypeErrorMessage(key, value, 'string'));
|
|
395
|
-
}
|
|
396
|
-
return;
|
|
397
|
-
}
|
|
398
|
-
if (key.endsWith('_name') || key.endsWith('_id')) {
|
|
399
|
-
// Enforce that fields ending with '_name' or '_id' are strings.
|
|
400
|
-
if (value != null && value != undefined && typeof value !== 'string') {
|
|
401
|
-
throw new Error(Logger.makeTypeErrorMessage(key, value, 'string'));
|
|
402
|
-
}
|
|
403
|
-
return;
|
|
404
|
-
}
|
|
405
|
-
if (key.endsWith('_count')) {
|
|
406
|
-
// Enforce that fields ending with '_count' are numbers.
|
|
407
|
-
if (value != null && value != undefined && typeof value !== 'number') {
|
|
408
|
-
throw new Error(Logger.makeTypeErrorMessage(key, value, 'number'));
|
|
409
|
-
}
|
|
410
|
-
return;
|
|
411
|
-
}
|
|
412
|
-
// We have to enforce field types, because the fields will be indexed in elasticsearch, and
|
|
413
|
-
// incorrect types will cause indexing errors. This is especially important for the well-known
|
|
414
|
-
// fields, but we also enforce it for all fields.
|
|
415
|
-
switch (key) {
|
|
416
|
-
case 'service_name':
|
|
417
|
-
case 'node_name':
|
|
418
|
-
case 'version':
|
|
419
|
-
case 'client_type':
|
|
420
|
-
case 'client_service_name':
|
|
421
|
-
case 'client_node_name':
|
|
422
|
-
case 'client_version':
|
|
423
|
-
case 'context':
|
|
424
|
-
case 'topic':
|
|
425
|
-
case 'subtopic':
|
|
426
|
-
case 'user_id':
|
|
427
|
-
case 'email':
|
|
428
|
-
case 'url':
|
|
429
|
-
case 'session_ref':
|
|
430
|
-
case 'content_kind':
|
|
431
|
-
case 'content_ref':
|
|
432
|
-
case 'bucket':
|
|
433
|
-
case 'name':
|
|
434
|
-
case 'file_name':
|
|
435
|
-
case 'request_body':
|
|
436
|
-
case 'original_data':
|
|
437
|
-
case 'transformed_data':
|
|
438
|
-
case 'error_body':
|
|
439
|
-
if (value != null && value != undefined && typeof value !== 'string') {
|
|
440
|
-
throw new Error(Logger.makeTypeErrorMessage(key, value, 'string'));
|
|
441
|
-
}
|
|
442
|
-
return;
|
|
443
|
-
case 'params':
|
|
444
|
-
if (value != null && value != undefined ) {
|
|
445
|
-
if (typeof value == 'string') {
|
|
446
|
-
// Validate that the string value used for this field is parseable as JSON.
|
|
447
|
-
try {
|
|
448
|
-
JSON.parse(value);
|
|
449
|
-
} catch (e) {
|
|
450
|
-
throw new Error(`invalid JSON for log field '${key}': ${value}`);
|
|
451
|
-
}
|
|
452
|
-
} else {
|
|
453
|
-
throw new Error(Logger.makeTypeErrorMessage(key, value, 'string'));
|
|
454
|
-
}
|
|
455
|
-
}
|
|
456
|
-
return;
|
|
457
|
-
case 'using_jwt':
|
|
458
|
-
case 'using_pass_hash':
|
|
459
|
-
case 'ignore_conflict':
|
|
460
|
-
if (value != null && value != undefined && typeof value !== 'boolean') {;
|
|
461
|
-
throw new Error(Logger.makeTypeErrorMessage(key, value, 'boolean'));
|
|
462
|
-
}
|
|
463
|
-
return;
|
|
464
|
-
case 'count':
|
|
465
|
-
case 'word_count':
|
|
466
|
-
case 'duration_millis':
|
|
467
|
-
case 'file_size':
|
|
468
|
-
case 'doc_version':
|
|
469
|
-
if (value != null && value != undefined && typeof value !== 'number') {
|
|
470
|
-
throw new Error(Logger.makeTypeErrorMessage(key, value, 'number'));
|
|
471
|
-
}
|
|
472
|
-
return;
|
|
473
|
-
}
|
|
474
|
-
if (typeof value !== 'string' && typeof value !== 'number' && typeof value !== 'boolean') {
|
|
475
|
-
throw new Error(`invalid type for log field '${key}': ${typeof value}`);
|
|
476
|
-
}
|
|
477
|
-
}
|
|
478
|
-
|
|
479
|
-
private static makeTypeErrorMessage(key:string, value:any, expectedType:string):string {
|
|
480
|
-
return `invalid type for log field '${key}': ${typeof value}; expected ${expectedType}`;
|
|
481
|
-
}
|
|
482
|
-
|
|
483
|
-
}
|
|
484
|
-
|
|
485
|
-
// The LogFields type is used to record structured data in log entries. It is a key-value object,
|
|
486
|
-
// with a set of well-known fields, and an open-ended set of additional fields. Part of the reason
|
|
487
|
-
// this interface definiton exists is to enforce the types on well-known fields (because they will
|
|
488
|
-
// be indexed into elasticsearch, and incorrect types for any of these fields will casuse indexing
|
|
489
|
-
// errors). This list can grow over time, as new well-known fields are added to the logging system.
|
|
490
|
-
export interface LogFields {
|
|
491
|
-
|
|
492
|
-
// 'service_name', 'version', and 'node_name' are used in server-logging, to record details about
|
|
493
|
-
// the service that recorded the log entry.
|
|
494
|
-
service_name?: string;
|
|
495
|
-
node_name?: string;
|
|
496
|
-
version?: string;
|
|
497
|
-
|
|
498
|
-
// 'client_type' and 'client_node_name' are used in server-logging, to record activities performed
|
|
499
|
-
// on behalf of either a user or another server node. Whenever 'client_type' is 'user', the 'user_id'
|
|
500
|
-
// field should be populated. Whenever 'client_type' is 'server', the 'client_node_name' field should
|
|
501
|
-
// be populated.
|
|
502
|
-
client_type?: ClientType;
|
|
503
|
-
client_service_name?: string;
|
|
504
|
-
client_node_name?: string;
|
|
505
|
-
client_version?: string;
|
|
506
|
-
|
|
507
|
-
// 'context' and 'name' are general-purpose fields used in all kinds of logging
|
|
508
|
-
context?: string;
|
|
509
|
-
name?: string;
|
|
510
|
-
|
|
511
|
-
// 'topic' and 'subtopic' are used in client-side activity tracking
|
|
512
|
-
topic?: string;
|
|
513
|
-
subtopic?: string;
|
|
514
|
-
|
|
515
|
-
// 'using_jwt' and 'using_pass_hash' are used in server-logging, to record whether the client is
|
|
516
|
-
// using a JWT or a password hash for authentication.
|
|
517
|
-
using_jwt?: boolean;
|
|
518
|
-
using_pass_hash?: boolean;
|
|
519
|
-
|
|
520
|
-
// 'user_id' and 'email' are used in all kinds of logging, anytime a specific user is relevant to the log entry.
|
|
521
|
-
user_id?: string;
|
|
522
|
-
email?: string;
|
|
523
|
-
url?: string;
|
|
524
|
-
|
|
525
|
-
// 'session_ref' is used in the desktop and browser clients, to record the session ID of the current session.
|
|
526
|
-
session_ref?: string;
|
|
527
|
-
|
|
528
|
-
// 'content_kind', 'content_ref', and 'doc_version' are used in all kinds of logging, to record
|
|
529
|
-
// the ShareDB identity and version of a relevant content item.
|
|
530
|
-
content_kind?: string;
|
|
531
|
-
content_ref?: string;
|
|
532
|
-
doc_version?: number;
|
|
533
|
-
|
|
534
|
-
// 'word_count' is used in all kinds of logging, to record the number of words in a relevant content item.
|
|
535
|
-
word_count?: number;
|
|
536
|
-
|
|
537
|
-
// 'bucket', 'file_name' and 'file_size' are used in all kinds of logging, to record the name and/or size of a relevant file
|
|
538
|
-
bucket?: string;
|
|
539
|
-
file_name?: string;
|
|
540
|
-
file_size?: number;
|
|
541
|
-
|
|
542
|
-
// 'count' and 'duration_millis' are used in all kinds of logging, with obvious meanings.
|
|
543
|
-
count?: number;
|
|
544
|
-
duration_millis?: number;
|
|
545
|
-
|
|
546
|
-
// 'request_body' and 'params' are used in server-logging, to record the body of an HTTP request,
|
|
547
|
-
// or the parameters of a function call. They are both strings, and should contain a JSON-serialized
|
|
548
|
-
// representation of the request body or parameters.
|
|
549
|
-
request_body?: string;
|
|
550
|
-
params?: string;
|
|
551
|
-
|
|
552
|
-
// 'original_data' and 'transformed_data' are used in all kinds of logging, to record the original
|
|
553
|
-
// and transformed data of a relevant content item. Since these are both strings, they should
|
|
554
|
-
// contain a JSON-serialized representation of the data.
|
|
555
|
-
original_data?: string;
|
|
556
|
-
transformed_data?: string;
|
|
557
|
-
|
|
558
|
-
// 'ignore_conflict' is used to record whether a conflict was ignored (e.g., during an elasticsearch indexing operation).
|
|
559
|
-
ignore_conflict?: boolean;
|
|
560
|
-
|
|
561
|
-
// 'error_body' is used in all logging, to record the body of any error object. Since it is a string field,
|
|
562
|
-
// it shoud contain a JSON-serialized representation of the error.
|
|
563
|
-
error_body?: string;
|
|
564
|
-
|
|
565
|
-
// This line in the LogFields type definition allows arbitrary fields to be added to the LogFields
|
|
566
|
-
// object, as long as the values are strings, numbers, or booleans.
|
|
567
|
-
[key: string]: string | number | boolean;
|
|
568
|
-
}
|
package/lib/util/index.ts
DELETED
package/tsconfig.json
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"module": "commonjs",
|
|
4
|
-
"outDir": "./dist",
|
|
5
|
-
"noImplicitAny": true,
|
|
6
|
-
"alwaysStrict": true,
|
|
7
|
-
"target": "es2021",
|
|
8
|
-
"declaration": true,
|
|
9
|
-
"moduleResolution": "node",
|
|
10
|
-
"resolveJsonModule": true,
|
|
11
|
-
"esModuleInterop": true,
|
|
12
|
-
"allowSyntheticDefaultImports":true,
|
|
13
|
-
"typeRoots": [
|
|
14
|
-
"./node_modules/@types"
|
|
15
|
-
]
|
|
16
|
-
},
|
|
17
|
-
"include": [
|
|
18
|
-
"./lib/**/*",
|
|
19
|
-
"decs.d.ts"
|
|
20
|
-
],
|
|
21
|
-
"baseUrl": "types",
|
|
22
|
-
"typeRoots": [
|
|
23
|
-
"types"
|
|
24
|
-
]
|
|
25
|
-
}
|
package/tslint.json
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "tslint:recommended",
|
|
3
|
-
"rules": {
|
|
4
|
-
"eofline": false,
|
|
5
|
-
"interface-name": false,
|
|
6
|
-
"max-classes-per-file": false,
|
|
7
|
-
"max-line-length": {
|
|
8
|
-
"options": [120]
|
|
9
|
-
},
|
|
10
|
-
"member-access": true,
|
|
11
|
-
"member-ordering": false,
|
|
12
|
-
"new-parens": true,
|
|
13
|
-
"no-arg": true,
|
|
14
|
-
"no-bitwise": true,
|
|
15
|
-
"no-conditional-assignment": true,
|
|
16
|
-
"no-consecutive-blank-lines": false,
|
|
17
|
-
"no-console": {
|
|
18
|
-
"severity": "warning",
|
|
19
|
-
"options": ["debug", "info", "log", "time", "timeEnd", "trace"]
|
|
20
|
-
},
|
|
21
|
-
"no-unused-variable": true,
|
|
22
|
-
"object-literal-key-quotes": false,
|
|
23
|
-
"object-literal-shorthand": false,
|
|
24
|
-
"object-literal-sort-keys": false,
|
|
25
|
-
"only-arrow-functions": false,
|
|
26
|
-
"prefer-const": false,
|
|
27
|
-
"prefer-for-of": false,
|
|
28
|
-
"quotemark": false,
|
|
29
|
-
"radix": false,
|
|
30
|
-
"trailing-comma": false,
|
|
31
|
-
"typedef": [true, "call-signature", "parameter"],
|
|
32
|
-
"typedef-whitespace": [true, {}, {
|
|
33
|
-
"call-signature": "nospace",
|
|
34
|
-
"parameter": "nospace",
|
|
35
|
-
"property-declaration": "nospace",
|
|
36
|
-
"variable-declaration": "nospace"
|
|
37
|
-
}],
|
|
38
|
-
"variable-name": false,
|
|
39
|
-
"whitespace": false
|
|
40
|
-
},
|
|
41
|
-
"jsRules": {
|
|
42
|
-
"max-line-length": {
|
|
43
|
-
"options": [120]
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}
|