@shaxpir/duiduidui-models 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/decs.d.ts +87 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +20 -0
- package/dist/models/OutboundMessage.d.ts +18 -0
- package/dist/models/OutboundMessage.js +25 -0
- package/dist/models/content/Activity.d.ts +10 -0
- package/dist/models/content/Activity.js +2 -0
- package/dist/models/content/ArrayView.d.ts +26 -0
- package/dist/models/content/ArrayView.js +174 -0
- package/dist/models/content/Billing.d.ts +144 -0
- package/dist/models/content/Billing.js +418 -0
- package/dist/models/content/Book.d.ts +77 -0
- package/dist/models/content/Book.js +407 -0
- package/dist/models/content/Category.d.ts +16 -0
- package/dist/models/content/Category.js +20 -0
- package/dist/models/content/Checkpointable.d.ts +21 -0
- package/dist/models/content/Checkpointable.js +156 -0
- package/dist/models/content/Comment.d.ts +19 -0
- package/dist/models/content/Comment.js +53 -0
- package/dist/models/content/ConceptArt.d.ts +31 -0
- package/dist/models/content/ConceptArt.js +84 -0
- package/dist/models/content/Content.d.ts +52 -0
- package/dist/models/content/Content.js +61 -0
- package/dist/models/content/ContentKind.d.ts +10 -0
- package/dist/models/content/ContentKind.js +16 -0
- package/dist/models/content/Context.d.ts +28 -0
- package/dist/models/content/Context.js +162 -0
- package/dist/models/content/DevEnv.d.ts +5 -0
- package/dist/models/content/DevEnv.js +9 -0
- package/dist/models/content/Device.d.ts +24 -0
- package/dist/models/content/Device.js +62 -0
- package/dist/models/content/Dictionary.d.ts +31 -0
- package/dist/models/content/Dictionary.js +5 -0
- package/dist/models/content/DictionaryEntry.d.ts +20 -0
- package/dist/models/content/DictionaryEntry.js +2 -0
- package/dist/models/content/ElasticModel.d.ts +149 -0
- package/dist/models/content/ElasticModel.js +179 -0
- package/dist/models/content/Environment.d.ts +61 -0
- package/dist/models/content/Environment.js +124 -0
- package/dist/models/content/ExportOptions.d.ts +64 -0
- package/dist/models/content/ExportOptions.js +213 -0
- package/dist/models/content/Folder.d.ts +16 -0
- package/dist/models/content/Folder.js +33 -0
- package/dist/models/content/Fragment.d.ts +54 -0
- package/dist/models/content/Fragment.js +181 -0
- package/dist/models/content/GeoLocation.d.ts +4 -0
- package/dist/models/content/GeoLocation.js +2 -0
- package/dist/models/content/Hanzi.d.ts +21 -0
- package/dist/models/content/Hanzi.js +2 -0
- package/dist/models/content/HighlightRule.d.ts +9 -0
- package/dist/models/content/HighlightRule.js +2 -0
- package/dist/models/content/Manifest.d.ts +42 -0
- package/dist/models/content/Manifest.js +114 -0
- package/dist/models/content/Media.d.ts +32 -0
- package/dist/models/content/Media.js +98 -0
- package/dist/models/content/Metric.d.ts +46 -0
- package/dist/models/content/Metric.js +183 -0
- package/dist/models/content/Migration.d.ts +68 -0
- package/dist/models/content/Migration.js +155 -0
- package/dist/models/content/Model.d.ts +45 -0
- package/dist/models/content/Model.js +280 -0
- package/dist/models/content/Permissions.d.ts +7 -0
- package/dist/models/content/Permissions.js +20 -0
- package/dist/models/content/Phrase.d.ts +8 -0
- package/dist/models/content/Phrase.js +2 -0
- package/dist/models/content/Placeholder.d.ts +8 -0
- package/dist/models/content/Placeholder.js +36 -0
- package/dist/models/content/Profile.d.ts +30 -0
- package/dist/models/content/Profile.js +95 -0
- package/dist/models/content/RichText.d.ts +58 -0
- package/dist/models/content/RichText.js +79 -0
- package/dist/models/content/Session.d.ts +39 -0
- package/dist/models/content/Session.js +173 -0
- package/dist/models/content/Speech.d.ts +67 -0
- package/dist/models/content/Speech.js +97 -0
- package/dist/models/content/Stub.d.ts +24 -0
- package/dist/models/content/Stub.js +179 -0
- package/dist/models/content/Time.d.ts +56 -0
- package/dist/models/content/Time.js +295 -0
- package/dist/models/content/User.d.ts +36 -0
- package/dist/models/content/User.js +95 -0
- package/dist/models/content/Workspace.d.ts +71 -0
- package/dist/models/content/Workspace.js +237 -0
- package/dist/models/content/index.d.ts +36 -0
- package/dist/models/content/index.js +53 -0
- package/dist/models/index.d.ts +4 -0
- package/dist/models/index.js +21 -0
- package/dist/models/legacy/LegacyBodyFormat.d.ts +9 -0
- package/dist/models/legacy/LegacyBodyFormat.js +2 -0
- package/dist/models/legacy/LegacyComment.d.ts +12 -0
- package/dist/models/legacy/LegacyComment.js +2 -0
- package/dist/models/legacy/LegacyContent.d.ts +53 -0
- package/dist/models/legacy/LegacyContent.js +55 -0
- package/dist/models/legacy/LegacyConversion.d.ts +55 -0
- package/dist/models/legacy/LegacyConversion.js +401 -0
- package/dist/models/legacy/LegacyFragment.d.ts +21 -0
- package/dist/models/legacy/LegacyFragment.js +2 -0
- package/dist/models/legacy/LegacyLocator.d.ts +8 -0
- package/dist/models/legacy/LegacyLocator.js +31 -0
- package/dist/models/legacy/LegacyOutboundMessage.d.ts +16 -0
- package/dist/models/legacy/LegacyOutboundMessage.js +13 -0
- package/dist/models/legacy/LegacyPicture.d.ts +14 -0
- package/dist/models/legacy/LegacyPicture.js +2 -0
- package/dist/models/legacy/LegacyProfile.d.ts +9 -0
- package/dist/models/legacy/LegacyProfile.js +2 -0
- package/dist/models/legacy/LegacySession.d.ts +41 -0
- package/dist/models/legacy/LegacySession.js +35 -0
- package/dist/models/legacy/LegacyStory.d.ts +23 -0
- package/dist/models/legacy/LegacyStory.js +2 -0
- package/dist/models/legacy/LegacyStub.d.ts +15 -0
- package/dist/models/legacy/LegacyStub.js +2 -0
- package/dist/models/legacy/LegacyTransaction.d.ts +14 -0
- package/dist/models/legacy/LegacyTransaction.js +49 -0
- package/dist/models/legacy/LegacyUser.d.ts +28 -0
- package/dist/models/legacy/LegacyUser.js +32 -0
- package/dist/models/legacy/LegacyWorkspace.d.ts +23 -0
- package/dist/models/legacy/LegacyWorkspace.js +6 -0
- package/dist/models/legacy/index.d.ts +15 -0
- package/dist/models/legacy/index.js +32 -0
- package/dist/models/markup/BodyFormat.d.ts +14 -0
- package/dist/models/markup/BodyFormat.js +190 -0
- package/dist/models/markup/ChangeModel.d.ts +22 -0
- package/dist/models/markup/ChangeModel.js +107 -0
- package/dist/models/markup/DeltaOps.d.ts +5 -0
- package/dist/models/markup/DeltaOps.js +74 -0
- package/dist/models/markup/HtmlMarkup.d.ts +4 -0
- package/dist/models/markup/HtmlMarkup.js +21 -0
- package/dist/models/markup/Operation.d.ts +32 -0
- package/dist/models/markup/Operation.js +194 -0
- package/dist/models/markup/TextEditOps.d.ts +9 -0
- package/dist/models/markup/TextEditOps.js +50 -0
- package/dist/models/markup/index.d.ts +6 -0
- package/dist/models/markup/index.js +23 -0
- package/dist/repo/ConnectionListener.d.ts +9 -0
- package/dist/repo/ConnectionListener.js +21 -0
- package/dist/repo/PermissiveJson1.d.ts +58 -0
- package/dist/repo/PermissiveJson1.js +39 -0
- package/dist/repo/ShareSync.d.ts +60 -0
- package/dist/repo/ShareSync.js +348 -0
- package/dist/repo/index.d.ts +3 -0
- package/dist/repo/index.js +20 -0
- package/dist/util/Async.d.ts +8 -0
- package/dist/util/Async.js +18 -0
- package/dist/util/Base62.d.ts +6 -0
- package/dist/util/Base62.js +47 -0
- package/dist/util/BinarySearch.d.ts +7 -0
- package/dist/util/BinarySearch.js +46 -0
- package/dist/util/CachingHasher.d.ts +8 -0
- package/dist/util/CachingHasher.js +41 -0
- package/dist/util/Color.d.ts +32 -0
- package/dist/util/Color.js +204 -0
- package/dist/util/Dispatch.d.ts +15 -0
- package/dist/util/Dispatch.js +79 -0
- package/dist/util/EditDistance.d.ts +13 -0
- package/dist/util/EditDistance.js +184 -0
- package/dist/util/Encryption.d.ts +5 -0
- package/dist/util/Encryption.js +2 -0
- package/dist/util/Logging.d.ts +108 -0
- package/dist/util/Logging.js +412 -0
- package/dist/util/NumberFormat.d.ts +14 -0
- package/dist/util/NumberFormat.js +224 -0
- package/dist/util/Struct.d.ts +4 -0
- package/dist/util/Struct.js +15 -0
- package/dist/util/Template.d.ts +16 -0
- package/dist/util/Template.js +128 -0
- package/dist/util/Text.d.ts +45 -0
- package/dist/util/Text.js +243 -0
- package/dist/util/Tuples.d.ts +9 -0
- package/dist/util/Tuples.js +135 -0
- package/dist/util/Validate.d.ts +4 -0
- package/dist/util/Validate.js +11 -0
- package/dist/util/Vocabulary.d.ts +3 -0
- package/dist/util/Vocabulary.js +35 -0
- package/dist/util/index.d.ts +16 -0
- package/dist/util/index.js +33 -0
- package/lib/models/content/ArrayView.ts +203 -0
- package/lib/models/content/Billing.ts +558 -0
- package/lib/models/content/Content.ts +110 -0
- package/lib/models/content/ContentKind.ts +14 -0
- package/lib/models/content/DevEnv.ts +5 -0
- package/lib/models/content/Device.ts +86 -0
- package/lib/models/content/DictionaryEntry.ts +22 -0
- package/lib/models/content/GeoLocation.ts +4 -0
- package/lib/models/content/Hanzi.ts +25 -0
- package/lib/models/content/Manifest.ts +162 -0
- package/lib/models/content/Media.ts +126 -0
- package/lib/models/content/Model.ts +327 -0
- package/lib/models/content/Permissions.ts +21 -0
- package/lib/models/content/Phrase.ts +10 -0
- package/lib/models/content/Profile.ts +119 -0
- package/lib/models/content/Time.ts +328 -0
- package/lib/models/content/User.ts +130 -0
- package/lib/models/markup/ChangeModel.ts +95 -0
- package/lib/models/markup/DeltaOps.ts +71 -0
- package/lib/models/markup/Operation.ts +215 -0
- package/lib/models/markup/TextEditOps.ts +50 -0
- package/lib/repo/ConnectionListener.ts +25 -0
- package/lib/repo/PermissiveJson1.ts +14 -0
- package/lib/repo/ShareSync.ts +390 -0
- package/lib/util/Base62.ts +47 -0
- package/lib/util/CachingHasher.ts +38 -0
- package/lib/util/Dispatch.ts +92 -0
- package/lib/util/Encryption.ts +5 -0
- package/lib/util/Logging.ts +568 -0
- package/lib/util/NumberFormat.ts +194 -0
- package/lib/util/Struct.ts +14 -0
- package/lib/util/Tuples.ts +131 -0
- package/package.json +41 -0
- package/tsconfig.json +25 -0
- package/tslint.json +46 -0
|
@@ -0,0 +1,412 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Logger = exports.ConsoleJsonLogRecorder = void 0;
|
|
4
|
+
class ConsoleJsonLogRecorder {
|
|
5
|
+
recordLogEntry(item) {
|
|
6
|
+
const stringified = JSON.stringify(item);
|
|
7
|
+
if (item.level === 'error') {
|
|
8
|
+
console.error(stringified);
|
|
9
|
+
}
|
|
10
|
+
else if (item.level === 'warn') {
|
|
11
|
+
console.warn(stringified);
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
console.log(stringified);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.ConsoleJsonLogRecorder = ConsoleJsonLogRecorder;
|
|
19
|
+
class Logger {
|
|
20
|
+
constructor(recorder) {
|
|
21
|
+
this.fields = {};
|
|
22
|
+
this.recorder = recorder;
|
|
23
|
+
}
|
|
24
|
+
/* static method for creating a new Logger instance, optionally with a context */
|
|
25
|
+
static create(recorder, context) {
|
|
26
|
+
const b = new Logger(recorder);
|
|
27
|
+
if (context) {
|
|
28
|
+
b.withContext(context);
|
|
29
|
+
}
|
|
30
|
+
return b;
|
|
31
|
+
}
|
|
32
|
+
/* method for cloning a Logger instance */
|
|
33
|
+
clone() {
|
|
34
|
+
const clone = new Logger(this.recorder);
|
|
35
|
+
clone.withTimestamp(this.timestamp);
|
|
36
|
+
clone.withLevel(this.level);
|
|
37
|
+
clone.withMessage(this.message);
|
|
38
|
+
clone.withFields(this.fields);
|
|
39
|
+
return clone;
|
|
40
|
+
}
|
|
41
|
+
/* method for sending a log entry, which must be called in order to record the log item */
|
|
42
|
+
send() {
|
|
43
|
+
let timestamp = this.timestamp;
|
|
44
|
+
if (!timestamp) {
|
|
45
|
+
timestamp = new Date().toISOString();
|
|
46
|
+
}
|
|
47
|
+
this.recorder.recordLogEntry({
|
|
48
|
+
timestamp: timestamp,
|
|
49
|
+
level: this.level,
|
|
50
|
+
message: this.message,
|
|
51
|
+
fields: this.fields
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
/* method for setting a level and message */
|
|
55
|
+
info(message) {
|
|
56
|
+
this.withLevel('info');
|
|
57
|
+
this.withMessage(message);
|
|
58
|
+
return this;
|
|
59
|
+
}
|
|
60
|
+
warn(message) {
|
|
61
|
+
this.withLevel('warn');
|
|
62
|
+
this.withMessage(message);
|
|
63
|
+
return this;
|
|
64
|
+
}
|
|
65
|
+
debug(message) {
|
|
66
|
+
this.withLevel('debug');
|
|
67
|
+
this.withMessage(message);
|
|
68
|
+
return this;
|
|
69
|
+
}
|
|
70
|
+
error(message, err) {
|
|
71
|
+
this.withLevel('error');
|
|
72
|
+
this.withMessage(message);
|
|
73
|
+
this.withError(err);
|
|
74
|
+
return this;
|
|
75
|
+
}
|
|
76
|
+
/* methods for setting intrinsic LogItem properties */
|
|
77
|
+
withTimestamp(timestamp) {
|
|
78
|
+
if (timestamp instanceof Date) {
|
|
79
|
+
this.timestamp = timestamp.toISOString();
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
this.timestamp = timestamp;
|
|
83
|
+
}
|
|
84
|
+
return this;
|
|
85
|
+
}
|
|
86
|
+
withLevel(level) {
|
|
87
|
+
this.level = level;
|
|
88
|
+
return this;
|
|
89
|
+
}
|
|
90
|
+
withMessage(message) {
|
|
91
|
+
this.message = message;
|
|
92
|
+
return this;
|
|
93
|
+
}
|
|
94
|
+
withFields(fields) {
|
|
95
|
+
// Iterate over all the new fields, and enforce the field types. Add them
|
|
96
|
+
// one-by-one using the withField method, which will enforce the field types.
|
|
97
|
+
let keys = Object.keys(fields);
|
|
98
|
+
for (let i = 0; i < keys.length; i++) {
|
|
99
|
+
let key = keys[i];
|
|
100
|
+
let value = fields[key];
|
|
101
|
+
this.withField(key, value);
|
|
102
|
+
}
|
|
103
|
+
return this;
|
|
104
|
+
}
|
|
105
|
+
withField(key, value) {
|
|
106
|
+
Logger.enforceFieldType(key, value);
|
|
107
|
+
if (value instanceof Date) {
|
|
108
|
+
value = value.toISOString();
|
|
109
|
+
}
|
|
110
|
+
this.fields[key] = value;
|
|
111
|
+
return this;
|
|
112
|
+
}
|
|
113
|
+
/* methods for setting specific fields, using appropriate types */
|
|
114
|
+
withServiceName(serviceName) {
|
|
115
|
+
this.withField('service_name', serviceName);
|
|
116
|
+
return this;
|
|
117
|
+
}
|
|
118
|
+
withNodeName(nodeName) {
|
|
119
|
+
this.withField('node_name', nodeName);
|
|
120
|
+
return this;
|
|
121
|
+
}
|
|
122
|
+
withVersion(version) {
|
|
123
|
+
this.withField('version', version);
|
|
124
|
+
return this;
|
|
125
|
+
}
|
|
126
|
+
withClientType(clientType) {
|
|
127
|
+
this.withField('client_type', clientType);
|
|
128
|
+
return this;
|
|
129
|
+
}
|
|
130
|
+
withClientServiceName(serviceName) {
|
|
131
|
+
this.withField('client_service_name', serviceName);
|
|
132
|
+
return this;
|
|
133
|
+
}
|
|
134
|
+
withClientNodeName(nodeName) {
|
|
135
|
+
this.withField('client_node_name', nodeName);
|
|
136
|
+
return this;
|
|
137
|
+
}
|
|
138
|
+
withClientVersion(version) {
|
|
139
|
+
this.withField('client_version', version);
|
|
140
|
+
return this;
|
|
141
|
+
}
|
|
142
|
+
withTopic(topic) {
|
|
143
|
+
this.withField('topic', topic);
|
|
144
|
+
return this;
|
|
145
|
+
}
|
|
146
|
+
withSubtopic(subtopic) {
|
|
147
|
+
this.withField('subtopic', subtopic);
|
|
148
|
+
return this;
|
|
149
|
+
}
|
|
150
|
+
withName(name) {
|
|
151
|
+
this.withField('name', name);
|
|
152
|
+
return this;
|
|
153
|
+
}
|
|
154
|
+
withContext(context) {
|
|
155
|
+
this.withField('context', context);
|
|
156
|
+
return this;
|
|
157
|
+
}
|
|
158
|
+
withUsingJwt(usingJwt) {
|
|
159
|
+
this.withField('using_jwt', usingJwt);
|
|
160
|
+
return this;
|
|
161
|
+
}
|
|
162
|
+
withUsingPassHash(usingPassHash) {
|
|
163
|
+
this.withField('using_pass_hash', usingPassHash);
|
|
164
|
+
return this;
|
|
165
|
+
}
|
|
166
|
+
withUserId(userId) {
|
|
167
|
+
this.withField('user_id', userId);
|
|
168
|
+
return this;
|
|
169
|
+
}
|
|
170
|
+
withEmail(email) {
|
|
171
|
+
this.withField('email', email);
|
|
172
|
+
return this;
|
|
173
|
+
}
|
|
174
|
+
withUrl(url) {
|
|
175
|
+
this.withField('url', url);
|
|
176
|
+
return this;
|
|
177
|
+
}
|
|
178
|
+
withSessionRef(sessionRef) {
|
|
179
|
+
this.withField('session_ref', sessionRef);
|
|
180
|
+
return this;
|
|
181
|
+
}
|
|
182
|
+
withContentKind(kind) {
|
|
183
|
+
this.withField('content_kind', kind);
|
|
184
|
+
return this;
|
|
185
|
+
}
|
|
186
|
+
withContentRef(ref) {
|
|
187
|
+
this.withField('content_ref', ref);
|
|
188
|
+
return this;
|
|
189
|
+
}
|
|
190
|
+
withCount(count) {
|
|
191
|
+
this.withField('count', count);
|
|
192
|
+
return this;
|
|
193
|
+
}
|
|
194
|
+
withDurationMillis(duration) {
|
|
195
|
+
this.withField('duration_millis', duration);
|
|
196
|
+
return this;
|
|
197
|
+
}
|
|
198
|
+
withDocVersion(version) {
|
|
199
|
+
this.withField('doc_version', version);
|
|
200
|
+
return this;
|
|
201
|
+
}
|
|
202
|
+
withWordCount(count) {
|
|
203
|
+
this.withField('word_count', count);
|
|
204
|
+
return this;
|
|
205
|
+
}
|
|
206
|
+
withBucket(bucket) {
|
|
207
|
+
this.withField('bucket', bucket);
|
|
208
|
+
return this;
|
|
209
|
+
}
|
|
210
|
+
withFileName(fileName) {
|
|
211
|
+
this.withField('file_name', fileName);
|
|
212
|
+
return this;
|
|
213
|
+
}
|
|
214
|
+
withFileSize(size) {
|
|
215
|
+
this.withField('file_size', size);
|
|
216
|
+
return this;
|
|
217
|
+
}
|
|
218
|
+
withRequestBody(body) {
|
|
219
|
+
this.withField('request_body', Logger.ensureStringified(body));
|
|
220
|
+
return this;
|
|
221
|
+
}
|
|
222
|
+
clearParams() {
|
|
223
|
+
delete this.fields.params;
|
|
224
|
+
return this;
|
|
225
|
+
}
|
|
226
|
+
withParams(params) {
|
|
227
|
+
// Layer in the new params over the old params, if they exist.
|
|
228
|
+
const oldParams = this.fields.params;
|
|
229
|
+
if (oldParams) {
|
|
230
|
+
let oldParamsObj;
|
|
231
|
+
try {
|
|
232
|
+
oldParamsObj = JSON.parse(oldParams);
|
|
233
|
+
}
|
|
234
|
+
catch (e) {
|
|
235
|
+
oldParamsObj = {};
|
|
236
|
+
}
|
|
237
|
+
this.fields.params = JSON.stringify({ ...oldParamsObj, ...params });
|
|
238
|
+
}
|
|
239
|
+
else {
|
|
240
|
+
this.fields.params = JSON.stringify(params);
|
|
241
|
+
}
|
|
242
|
+
return this;
|
|
243
|
+
}
|
|
244
|
+
withChangingData(originalData, transformedData) {
|
|
245
|
+
this.withOriginalData(originalData);
|
|
246
|
+
this.withTransformedData(transformedData);
|
|
247
|
+
return this;
|
|
248
|
+
}
|
|
249
|
+
withOriginalData(data) {
|
|
250
|
+
this.withField('original_data', Logger.ensureStringified(data));
|
|
251
|
+
return this;
|
|
252
|
+
}
|
|
253
|
+
withTransformedData(data) {
|
|
254
|
+
this.withField('transformed_data', Logger.ensureStringified(data));
|
|
255
|
+
return this;
|
|
256
|
+
}
|
|
257
|
+
withIgnoreConflict(ignoreConflict) {
|
|
258
|
+
this.withField('ignore_conflict', ignoreConflict);
|
|
259
|
+
return this;
|
|
260
|
+
}
|
|
261
|
+
withError(err) {
|
|
262
|
+
let stringified;
|
|
263
|
+
if (err != null && err != undefined) {
|
|
264
|
+
if (typeof err === 'string') {
|
|
265
|
+
stringified = err;
|
|
266
|
+
}
|
|
267
|
+
else if (err instanceof Error) {
|
|
268
|
+
// If this is a structured error object, it might have circular references, so handle that
|
|
269
|
+
// with the 'inspect' function. First, attempt to use a normal JSON.stringify() operation,
|
|
270
|
+
// and if that fails, (probably because of circular refs) then fall back to using 'inspect'.
|
|
271
|
+
try {
|
|
272
|
+
stringified = JSON.stringify(err);
|
|
273
|
+
if (stringified === '{}') {
|
|
274
|
+
stringified = this.recorder.inspect(err);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
catch (e) {
|
|
278
|
+
stringified = this.recorder.inspect(err);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
else {
|
|
282
|
+
stringified = JSON.stringify(err);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
if (stringified) {
|
|
286
|
+
this.withField('error_body', stringified);
|
|
287
|
+
}
|
|
288
|
+
return this;
|
|
289
|
+
}
|
|
290
|
+
static ensureStringified(value) {
|
|
291
|
+
if (typeof value === 'string') {
|
|
292
|
+
return value;
|
|
293
|
+
}
|
|
294
|
+
else {
|
|
295
|
+
return JSON.stringify(value);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
static enforceFieldType(key, value) {
|
|
299
|
+
// Users can pass in Date values for fields that end with '_time' or '_date'. Those will be recorded
|
|
300
|
+
// as strings in the log entry, but we need to enforce that the field keys end with '_time' or '_date'.
|
|
301
|
+
// Likewise, if fields end with these suffixes, we need to enforce that the values either be strings
|
|
302
|
+
// that can be parsed as Dates, or actual Date objects (which will be stringified in the withField method).
|
|
303
|
+
if (value instanceof Date) {
|
|
304
|
+
if (key.endsWith('_time') || key.endsWith('_date')) {
|
|
305
|
+
return;
|
|
306
|
+
}
|
|
307
|
+
else {
|
|
308
|
+
throw new Error(`date field keys must end with '_time' or '_date': ${key}`);
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
else if (key.endsWith('_time') || key.endsWith('_date')) {
|
|
312
|
+
// Enforce that fields ending with '_time' or '_date' are strings or Dates.
|
|
313
|
+
if (typeof value == 'string') {
|
|
314
|
+
// Validate that the string value used for this field is parseable as a Date.
|
|
315
|
+
let date = new Date(value);
|
|
316
|
+
if (isNaN(date.getTime())) {
|
|
317
|
+
throw new Error(`invalid date for log field '${key}': ${value}`);
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
else {
|
|
321
|
+
throw new Error(Logger.makeTypeErrorMessage(key, value, 'string'));
|
|
322
|
+
}
|
|
323
|
+
return;
|
|
324
|
+
}
|
|
325
|
+
if (key.endsWith('_name') || key.endsWith('_id')) {
|
|
326
|
+
// Enforce that fields ending with '_name' or '_id' are strings.
|
|
327
|
+
if (value != null && value != undefined && typeof value !== 'string') {
|
|
328
|
+
throw new Error(Logger.makeTypeErrorMessage(key, value, 'string'));
|
|
329
|
+
}
|
|
330
|
+
return;
|
|
331
|
+
}
|
|
332
|
+
if (key.endsWith('_count')) {
|
|
333
|
+
// Enforce that fields ending with '_count' are numbers.
|
|
334
|
+
if (value != null && value != undefined && typeof value !== 'number') {
|
|
335
|
+
throw new Error(Logger.makeTypeErrorMessage(key, value, 'number'));
|
|
336
|
+
}
|
|
337
|
+
return;
|
|
338
|
+
}
|
|
339
|
+
// We have to enforce field types, because the fields will be indexed in elasticsearch, and
|
|
340
|
+
// incorrect types will cause indexing errors. This is especially important for the well-known
|
|
341
|
+
// fields, but we also enforce it for all fields.
|
|
342
|
+
switch (key) {
|
|
343
|
+
case 'service_name':
|
|
344
|
+
case 'node_name':
|
|
345
|
+
case 'version':
|
|
346
|
+
case 'client_type':
|
|
347
|
+
case 'client_service_name':
|
|
348
|
+
case 'client_node_name':
|
|
349
|
+
case 'client_version':
|
|
350
|
+
case 'context':
|
|
351
|
+
case 'topic':
|
|
352
|
+
case 'subtopic':
|
|
353
|
+
case 'user_id':
|
|
354
|
+
case 'email':
|
|
355
|
+
case 'url':
|
|
356
|
+
case 'session_ref':
|
|
357
|
+
case 'content_kind':
|
|
358
|
+
case 'content_ref':
|
|
359
|
+
case 'bucket':
|
|
360
|
+
case 'name':
|
|
361
|
+
case 'file_name':
|
|
362
|
+
case 'request_body':
|
|
363
|
+
case 'original_data':
|
|
364
|
+
case 'transformed_data':
|
|
365
|
+
case 'error_body':
|
|
366
|
+
if (value != null && value != undefined && typeof value !== 'string') {
|
|
367
|
+
throw new Error(Logger.makeTypeErrorMessage(key, value, 'string'));
|
|
368
|
+
}
|
|
369
|
+
return;
|
|
370
|
+
case 'params':
|
|
371
|
+
if (value != null && value != undefined) {
|
|
372
|
+
if (typeof value == 'string') {
|
|
373
|
+
// Validate that the string value used for this field is parseable as JSON.
|
|
374
|
+
try {
|
|
375
|
+
JSON.parse(value);
|
|
376
|
+
}
|
|
377
|
+
catch (e) {
|
|
378
|
+
throw new Error(`invalid JSON for log field '${key}': ${value}`);
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
else {
|
|
382
|
+
throw new Error(Logger.makeTypeErrorMessage(key, value, 'string'));
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
return;
|
|
386
|
+
case 'using_jwt':
|
|
387
|
+
case 'using_pass_hash':
|
|
388
|
+
case 'ignore_conflict':
|
|
389
|
+
if (value != null && value != undefined && typeof value !== 'boolean') {
|
|
390
|
+
;
|
|
391
|
+
throw new Error(Logger.makeTypeErrorMessage(key, value, 'boolean'));
|
|
392
|
+
}
|
|
393
|
+
return;
|
|
394
|
+
case 'count':
|
|
395
|
+
case 'word_count':
|
|
396
|
+
case 'duration_millis':
|
|
397
|
+
case 'file_size':
|
|
398
|
+
case 'doc_version':
|
|
399
|
+
if (value != null && value != undefined && typeof value !== 'number') {
|
|
400
|
+
throw new Error(Logger.makeTypeErrorMessage(key, value, 'number'));
|
|
401
|
+
}
|
|
402
|
+
return;
|
|
403
|
+
}
|
|
404
|
+
if (typeof value !== 'string' && typeof value !== 'number' && typeof value !== 'boolean') {
|
|
405
|
+
throw new Error(`invalid type for log field '${key}': ${typeof value}`);
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
static makeTypeErrorMessage(key, value, expectedType) {
|
|
409
|
+
return `invalid type for log field '${key}': ${typeof value}; expected ${expectedType}`;
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
exports.Logger = Logger;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare class NumberFormat {
|
|
2
|
+
private static readonly ORDINAL_REGEX;
|
|
3
|
+
private static readonly NUMERIC_WORD_SEQUENCE;
|
|
4
|
+
private static readonly ROMAN_NUMERALS;
|
|
5
|
+
static commas(value: number, keepFractions: boolean): string;
|
|
6
|
+
static ordinal(value: number): string;
|
|
7
|
+
static isOrdinal(text: string): boolean;
|
|
8
|
+
static dollarsFromCents(value: number): string;
|
|
9
|
+
static percent(value: number, fractionDigits?: number): string;
|
|
10
|
+
static text(value: number): string;
|
|
11
|
+
static findNumericWordSequence(text: string): string;
|
|
12
|
+
static findRomanNumerals(text: string): string;
|
|
13
|
+
static asHex(value: number, padToLength?: number): string;
|
|
14
|
+
}
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NumberFormat = void 0;
|
|
4
|
+
class NumberFormat {
|
|
5
|
+
static commas(value, keepFractions) {
|
|
6
|
+
if (!Number.isFinite(value)) {
|
|
7
|
+
return "0"; // We never want to show "NaN" or "Infinity" in shaxpir. Zero is always preferable.
|
|
8
|
+
}
|
|
9
|
+
let original = value;
|
|
10
|
+
let isNegative = value < 0;
|
|
11
|
+
let absValue = Math.abs(value);
|
|
12
|
+
let floorValue = Math.floor(absValue);
|
|
13
|
+
let v = floorValue;
|
|
14
|
+
let formatted = "";
|
|
15
|
+
if (v === 0) {
|
|
16
|
+
formatted = "0";
|
|
17
|
+
}
|
|
18
|
+
while (v > 0) {
|
|
19
|
+
if (formatted.length > 0) {
|
|
20
|
+
formatted = "," + formatted;
|
|
21
|
+
}
|
|
22
|
+
let remainder = (v % 1000);
|
|
23
|
+
v = Math.floor(v / 1000);
|
|
24
|
+
if (v > 0) {
|
|
25
|
+
if (remainder < 10) {
|
|
26
|
+
formatted = "00" + remainder + formatted;
|
|
27
|
+
}
|
|
28
|
+
else if (remainder < 100) {
|
|
29
|
+
formatted = "0" + remainder + formatted;
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
formatted = remainder + formatted;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
formatted = remainder + formatted;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
if (keepFractions && absValue !== floorValue) {
|
|
40
|
+
formatted += "." + original.toString().split('.')[1];
|
|
41
|
+
}
|
|
42
|
+
if (isNegative) {
|
|
43
|
+
formatted = "-" + formatted;
|
|
44
|
+
}
|
|
45
|
+
return formatted;
|
|
46
|
+
}
|
|
47
|
+
static ordinal(value) {
|
|
48
|
+
if (value == 1 || (value % 10 == 1 && value != 11)) {
|
|
49
|
+
return "st";
|
|
50
|
+
}
|
|
51
|
+
else if (value == 2 || (value % 10 == 2 && value != 12)) {
|
|
52
|
+
return "nd";
|
|
53
|
+
}
|
|
54
|
+
else if (value == 3 || (value % 10 == 3 && value != 13)) {
|
|
55
|
+
return "rd";
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
return "th";
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
static isOrdinal(text) {
|
|
62
|
+
return NumberFormat.ORDINAL_REGEX.test(text);
|
|
63
|
+
}
|
|
64
|
+
static dollarsFromCents(value) {
|
|
65
|
+
let dollars = Math.floor(value / 100);
|
|
66
|
+
let cents = value - (dollars * 100);
|
|
67
|
+
if (cents === 0) {
|
|
68
|
+
return "$" + dollars + ".00";
|
|
69
|
+
}
|
|
70
|
+
else if (cents < 10) {
|
|
71
|
+
return "$" + dollars + ".0" + cents;
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
return "$" + dollars + "." + cents;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
static percent(value, fractionDigits = 0) {
|
|
78
|
+
let numbers = NumberFormat.commas(value * 100, fractionDigits > 0);
|
|
79
|
+
if (fractionDigits > 0 && value !== 0) {
|
|
80
|
+
let indexOfDecimal = numbers.lastIndexOf(".");
|
|
81
|
+
if (indexOfDecimal >= 0) {
|
|
82
|
+
let numsBeforeDecimal = numbers.substring(0, indexOfDecimal);
|
|
83
|
+
let numsAfterDecimal = numbers.substring(indexOfDecimal + 1);
|
|
84
|
+
if (numsAfterDecimal.length > fractionDigits) {
|
|
85
|
+
numbers = numsBeforeDecimal + "." + numsAfterDecimal.substring(0, fractionDigits);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return numbers + "%";
|
|
90
|
+
}
|
|
91
|
+
static text(value) {
|
|
92
|
+
let isNegative = value < 0;
|
|
93
|
+
value = Math.abs(Math.round(value));
|
|
94
|
+
let asText;
|
|
95
|
+
if (value == 0) {
|
|
96
|
+
asText = "zero";
|
|
97
|
+
}
|
|
98
|
+
else if (value == 1) {
|
|
99
|
+
asText = "one";
|
|
100
|
+
}
|
|
101
|
+
else if (value == 2) {
|
|
102
|
+
asText = "two";
|
|
103
|
+
}
|
|
104
|
+
else if (value == 3) {
|
|
105
|
+
asText = "three";
|
|
106
|
+
}
|
|
107
|
+
else if (value == 4) {
|
|
108
|
+
asText = "four";
|
|
109
|
+
}
|
|
110
|
+
else if (value == 5) {
|
|
111
|
+
asText = "five";
|
|
112
|
+
}
|
|
113
|
+
else if (value == 6) {
|
|
114
|
+
asText = "six";
|
|
115
|
+
}
|
|
116
|
+
else if (value == 7) {
|
|
117
|
+
asText = "seven";
|
|
118
|
+
}
|
|
119
|
+
else if (value == 8) {
|
|
120
|
+
asText = "eight";
|
|
121
|
+
}
|
|
122
|
+
else if (value == 9) {
|
|
123
|
+
asText = "nine";
|
|
124
|
+
}
|
|
125
|
+
else if (value == 10) {
|
|
126
|
+
asText = "ten";
|
|
127
|
+
}
|
|
128
|
+
else if (value == 11) {
|
|
129
|
+
asText = "eleven";
|
|
130
|
+
}
|
|
131
|
+
else if (value == 12) {
|
|
132
|
+
asText = "twelve";
|
|
133
|
+
}
|
|
134
|
+
else if (value == 13) {
|
|
135
|
+
asText = "thirteen";
|
|
136
|
+
}
|
|
137
|
+
else if (value == 14) {
|
|
138
|
+
asText = "fourteen";
|
|
139
|
+
}
|
|
140
|
+
else if (value == 15) {
|
|
141
|
+
asText = "fifteen";
|
|
142
|
+
}
|
|
143
|
+
else if (value == 16) {
|
|
144
|
+
asText = "sixteen";
|
|
145
|
+
}
|
|
146
|
+
else if (value == 17) {
|
|
147
|
+
asText = "seventeen";
|
|
148
|
+
}
|
|
149
|
+
else if (value == 18) {
|
|
150
|
+
asText = "eighteen";
|
|
151
|
+
}
|
|
152
|
+
else if (value == 19) {
|
|
153
|
+
asText = "nineteen";
|
|
154
|
+
}
|
|
155
|
+
else if (value >= 20 && value <= 99) {
|
|
156
|
+
let tensPlace = Math.floor(value / 10);
|
|
157
|
+
let onesPlace = value % 10;
|
|
158
|
+
if (tensPlace == 2) {
|
|
159
|
+
asText = "twenty";
|
|
160
|
+
}
|
|
161
|
+
else if (tensPlace == 3) {
|
|
162
|
+
asText = "thirty";
|
|
163
|
+
}
|
|
164
|
+
else if (tensPlace == 4) {
|
|
165
|
+
asText = "forty";
|
|
166
|
+
}
|
|
167
|
+
else if (tensPlace == 5) {
|
|
168
|
+
asText = "fifty";
|
|
169
|
+
}
|
|
170
|
+
else if (tensPlace == 6) {
|
|
171
|
+
asText = "sixty";
|
|
172
|
+
}
|
|
173
|
+
else if (tensPlace == 7) {
|
|
174
|
+
asText = "seventy";
|
|
175
|
+
}
|
|
176
|
+
else if (tensPlace == 8) {
|
|
177
|
+
asText = "eighty";
|
|
178
|
+
}
|
|
179
|
+
else if (tensPlace == 9) {
|
|
180
|
+
asText = "ninety";
|
|
181
|
+
}
|
|
182
|
+
if (onesPlace !== 0) {
|
|
183
|
+
asText += "-" + NumberFormat.text(onesPlace);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
else if (value >= 100 && value <= 999) {
|
|
187
|
+
let hundredsPlace = Math.floor(value / 100);
|
|
188
|
+
asText = NumberFormat.text(hundredsPlace) + " hundred " + NumberFormat.text(value - (hundredsPlace * 100));
|
|
189
|
+
}
|
|
190
|
+
else if (value >= 1000 && value <= 9999) {
|
|
191
|
+
let thousandsPlace = Math.floor(value / 1000);
|
|
192
|
+
asText = NumberFormat.text(thousandsPlace) + " thousand " + NumberFormat.text(value - (thousandsPlace * 1000));
|
|
193
|
+
}
|
|
194
|
+
if (isNegative) {
|
|
195
|
+
asText = "minus " + asText;
|
|
196
|
+
}
|
|
197
|
+
return asText;
|
|
198
|
+
}
|
|
199
|
+
static findNumericWordSequence(text) {
|
|
200
|
+
let result = NumberFormat.NUMERIC_WORD_SEQUENCE.exec(text);
|
|
201
|
+
if (result !== null) {
|
|
202
|
+
return result[0];
|
|
203
|
+
}
|
|
204
|
+
return null;
|
|
205
|
+
}
|
|
206
|
+
static findRomanNumerals(text) {
|
|
207
|
+
let result = NumberFormat.ROMAN_NUMERALS.exec(text);
|
|
208
|
+
if (result !== null) {
|
|
209
|
+
return result[0];
|
|
210
|
+
}
|
|
211
|
+
return null;
|
|
212
|
+
}
|
|
213
|
+
static asHex(value, padToLength = 1) {
|
|
214
|
+
let hex = Math.floor(value).toString(16);
|
|
215
|
+
while (hex.length < padToLength) {
|
|
216
|
+
hex = "0" + hex;
|
|
217
|
+
}
|
|
218
|
+
return hex;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
exports.NumberFormat = NumberFormat;
|
|
222
|
+
NumberFormat.ORDINAL_REGEX = /^\d*(?:1st|2nd|3rd|[04-9]th|1[23]th)$/i;
|
|
223
|
+
NumberFormat.NUMERIC_WORD_SEQUENCE = /(?:one|two|three|four|five|six|seven|eight|nine|ten|eleven|twelve|(?:thir|four|fif|six|seven|eigh|nine)teen|(?:twen|thir|for|fif|six|seven|eigh|nine)ty|[mb]illion|thousand|hundred)(?:(?:\s*(?:\sand\s+|-\s*)(?:one|two|three|four|five|six|seven|eight|nine|ten|eleven|twelve|(?:thir|four|fif|six|seven|eigh|nine)teen|(?:twen|thir|for|fif|six|seven|eigh|nine)ty|[mb]illion|thousand|hundred)))*/i;
|
|
224
|
+
NumberFormat.ROMAN_NUMERALS = /\b[MDCLXVI]+\b/i;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Struct = void 0;
|
|
4
|
+
const rfdc = require("rfdc");
|
|
5
|
+
const isEqual = require("fast-deep-equal");
|
|
6
|
+
const cloneDeep = rfdc();
|
|
7
|
+
class Struct {
|
|
8
|
+
static clone(value) {
|
|
9
|
+
return cloneDeep(value);
|
|
10
|
+
}
|
|
11
|
+
static equals(a, b) {
|
|
12
|
+
return isEqual(a, b);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.Struct = Struct;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare class TemplateParser {
|
|
2
|
+
private static TAG_PATTERN;
|
|
3
|
+
static parse(text: string): Template;
|
|
4
|
+
private static fromChunks;
|
|
5
|
+
private static findEndIndex;
|
|
6
|
+
}
|
|
7
|
+
export interface Renderable {
|
|
8
|
+
render: (params: any) => string;
|
|
9
|
+
}
|
|
10
|
+
export declare class Template implements Renderable {
|
|
11
|
+
private parts;
|
|
12
|
+
private name;
|
|
13
|
+
private negated;
|
|
14
|
+
constructor(parts: Renderable[], name: string, negated: boolean);
|
|
15
|
+
render(params: any): string;
|
|
16
|
+
}
|