@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,204 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Color = exports.HSV = exports.HSLUV = exports.RGB = void 0;
|
|
4
|
+
const hsluv_1 = require("hsluv");
|
|
5
|
+
const NumberFormat_1 = require("./NumberFormat");
|
|
6
|
+
class RGB {
|
|
7
|
+
constructor(r, g, b) {
|
|
8
|
+
this.r = r;
|
|
9
|
+
this.g = g;
|
|
10
|
+
this.b = b;
|
|
11
|
+
}
|
|
12
|
+
toHEX() {
|
|
13
|
+
return "#" +
|
|
14
|
+
NumberFormat_1.NumberFormat.asHex(this.r, 2) +
|
|
15
|
+
NumberFormat_1.NumberFormat.asHex(this.g, 2) +
|
|
16
|
+
NumberFormat_1.NumberFormat.asHex(this.b, 2);
|
|
17
|
+
}
|
|
18
|
+
toHSV() {
|
|
19
|
+
let r = this.r;
|
|
20
|
+
let g = this.g;
|
|
21
|
+
let b = this.b;
|
|
22
|
+
let max = Math.max(r, g, b);
|
|
23
|
+
let min = Math.min(r, g, b);
|
|
24
|
+
let d = max - min;
|
|
25
|
+
let h;
|
|
26
|
+
switch (max) {
|
|
27
|
+
case min:
|
|
28
|
+
h = 0;
|
|
29
|
+
break;
|
|
30
|
+
case r:
|
|
31
|
+
h = (g - b) + d * (g < b ? 6 : 0);
|
|
32
|
+
h /= 6 * d;
|
|
33
|
+
break;
|
|
34
|
+
case g:
|
|
35
|
+
h = (b - r) + d * 2;
|
|
36
|
+
h /= 6 * d;
|
|
37
|
+
break;
|
|
38
|
+
case b:
|
|
39
|
+
h = (r - g) + d * 4;
|
|
40
|
+
h /= 6 * d;
|
|
41
|
+
break;
|
|
42
|
+
}
|
|
43
|
+
let s = max === 0 ? 0 : d / max;
|
|
44
|
+
let v = max / 255;
|
|
45
|
+
return new HSV(h, s, v);
|
|
46
|
+
}
|
|
47
|
+
toHSLUV() {
|
|
48
|
+
const converter = new hsluv_1.Hsluv();
|
|
49
|
+
converter.rgb_r = this.r / 255;
|
|
50
|
+
converter.rgb_g = this.g / 255;
|
|
51
|
+
converter.rgb_b = this.b / 255;
|
|
52
|
+
converter.rgbToHsluv();
|
|
53
|
+
const h = converter.hsluv_h;
|
|
54
|
+
const s = converter.hsluv_s;
|
|
55
|
+
const l = converter.hsluv_l;
|
|
56
|
+
return new HSLUV(h, s, l);
|
|
57
|
+
}
|
|
58
|
+
static parse(color) {
|
|
59
|
+
// match RGB values formatted as "rgb(12,34,56)" (with optional whitespace)
|
|
60
|
+
let match = /^\s*rgb\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)\s*$/i.exec(color);
|
|
61
|
+
if (match !== null) {
|
|
62
|
+
return new RGB(parseInt(match[1]), parseInt(match[2]), parseInt(match[3]));
|
|
63
|
+
}
|
|
64
|
+
// match RGB values formatted as "#AABBCC" (with optional #hash prefix)
|
|
65
|
+
match = /^#?([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i.exec(color);
|
|
66
|
+
if (match !== null) {
|
|
67
|
+
return new RGB(parseInt(match[1], 16), parseInt(match[2], 16), parseInt(match[3], 16));
|
|
68
|
+
}
|
|
69
|
+
// match RGB values formatted as "#ABC" (with optional #hash prefix)
|
|
70
|
+
match = /^#?([0-9a-f])([0-9a-f])([0-9a-f])$/i.exec(color);
|
|
71
|
+
if (match !== null) {
|
|
72
|
+
const red = match[1] + match[1];
|
|
73
|
+
const grn = match[2] + match[2];
|
|
74
|
+
const blu = match[3] + match[3];
|
|
75
|
+
return new RGB(parseInt(red, 16), parseInt(grn, 16), parseInt(blu, 16));
|
|
76
|
+
}
|
|
77
|
+
throw Error("can\x27t parse color: " + color);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
exports.RGB = RGB;
|
|
81
|
+
// We get better interpolations by using a perceptually uniform color space...
|
|
82
|
+
// https://programmingdesignsystems.com/color/perceptually-uniform-color-spaces/
|
|
83
|
+
class HSLUV {
|
|
84
|
+
constructor(h, s, l) {
|
|
85
|
+
this.h = h;
|
|
86
|
+
this.s = s;
|
|
87
|
+
this.l = l;
|
|
88
|
+
}
|
|
89
|
+
toRGB() {
|
|
90
|
+
let h = this.h;
|
|
91
|
+
let s = this.s;
|
|
92
|
+
let l = this.l;
|
|
93
|
+
let converter = new hsluv_1.Hsluv();
|
|
94
|
+
converter.hsluv_h = h;
|
|
95
|
+
converter.hsluv_s = s;
|
|
96
|
+
converter.hsluv_l = l;
|
|
97
|
+
converter.hsluvToRgb();
|
|
98
|
+
let r = Math.round(converter.rgb_r * 255);
|
|
99
|
+
let g = Math.round(converter.rgb_g * 255);
|
|
100
|
+
let b = Math.round(converter.rgb_b * 255);
|
|
101
|
+
return new RGB(r, g, b);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
exports.HSLUV = HSLUV;
|
|
105
|
+
class HSV {
|
|
106
|
+
constructor(h, s, v) {
|
|
107
|
+
this.h = h;
|
|
108
|
+
this.s = s;
|
|
109
|
+
this.v = v;
|
|
110
|
+
}
|
|
111
|
+
toRGB() {
|
|
112
|
+
let h = this.h;
|
|
113
|
+
let s = this.s;
|
|
114
|
+
let v = this.v;
|
|
115
|
+
let i = Math.floor(h * 6);
|
|
116
|
+
let f = h * 6 - i;
|
|
117
|
+
let p = v * (1 - s);
|
|
118
|
+
let q = v * (1 - f * s);
|
|
119
|
+
let t = v * (1 - (1 - f) * s);
|
|
120
|
+
let r, g, b;
|
|
121
|
+
switch (i % 6) {
|
|
122
|
+
case 0:
|
|
123
|
+
r = v, g = t, b = p;
|
|
124
|
+
break;
|
|
125
|
+
case 1:
|
|
126
|
+
r = q, g = v, b = p;
|
|
127
|
+
break;
|
|
128
|
+
case 2:
|
|
129
|
+
r = p, g = v, b = t;
|
|
130
|
+
break;
|
|
131
|
+
case 3:
|
|
132
|
+
r = p, g = q, b = v;
|
|
133
|
+
break;
|
|
134
|
+
case 4:
|
|
135
|
+
r = t, g = p, b = v;
|
|
136
|
+
break;
|
|
137
|
+
case 5:
|
|
138
|
+
r = v, g = p, b = q;
|
|
139
|
+
break;
|
|
140
|
+
}
|
|
141
|
+
return new RGB(Math.round(r * 255), Math.round(g * 255), Math.round(b * 255));
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
exports.HSV = HSV;
|
|
145
|
+
class Color {
|
|
146
|
+
static normalize(color) {
|
|
147
|
+
let rgb = RGB.parse(color);
|
|
148
|
+
return rgb.toHEX();
|
|
149
|
+
}
|
|
150
|
+
static makeShadeOf(color, hslOverride) {
|
|
151
|
+
let rgb = RGB.parse(color);
|
|
152
|
+
let hsluv = rgb.toHSLUV();
|
|
153
|
+
if (hslOverride.hasOwnProperty("h")) {
|
|
154
|
+
hsluv.h = hslOverride.h;
|
|
155
|
+
}
|
|
156
|
+
if (hslOverride.hasOwnProperty("s")) {
|
|
157
|
+
hsluv.s = hslOverride.s;
|
|
158
|
+
}
|
|
159
|
+
if (hslOverride.hasOwnProperty("l")) {
|
|
160
|
+
hsluv.l = hslOverride.l;
|
|
161
|
+
}
|
|
162
|
+
rgb = hsluv.toRGB();
|
|
163
|
+
return rgb.toHEX();
|
|
164
|
+
}
|
|
165
|
+
static interpolate(loColor, hiColor, steps, percent) {
|
|
166
|
+
// NOTE: Unlike HSV (where all 3 values are floats between 0 and 1), the HSLUV color space
|
|
167
|
+
// has a hue value between 0 and 360, and saturation and lightness values between 0 and 100.
|
|
168
|
+
let loRGB = RGB.parse(loColor);
|
|
169
|
+
let hiRGB = RGB.parse(hiColor);
|
|
170
|
+
// There's no point interpolating if the number of steps is only 2.
|
|
171
|
+
if (steps === 2) {
|
|
172
|
+
return percent > 0.5 ? hiRGB.toHEX() : loRGB.toHEX();
|
|
173
|
+
}
|
|
174
|
+
let loHSLUV = loRGB.toHSLUV();
|
|
175
|
+
let hiHSLUV = hiRGB.toHSLUV();
|
|
176
|
+
// If one of the colors is completely desaturated, it should share the same hue as the other color
|
|
177
|
+
if (loHSLUV.s < Color.EPSILON_SATURATION)
|
|
178
|
+
loHSLUV.h = hiHSLUV.h;
|
|
179
|
+
if (hiHSLUV.s < Color.EPSILON_SATURATION)
|
|
180
|
+
hiHSLUV.h = loHSLUV.h;
|
|
181
|
+
let clockwiseDiff = (loHSLUV.h >= hiHSLUV.h) ? 1 + hiHSLUV.h - loHSLUV.h : hiHSLUV.h - loHSLUV.h;
|
|
182
|
+
let counterClockwiseDiff = (loHSLUV.h >= hiHSLUV.h) ? loHSLUV.h - hiHSLUV.h : 1 + loHSLUV.h - hiHSLUV.h;
|
|
183
|
+
// Quantize the percentage to a certain number of discreet color steps.
|
|
184
|
+
// We've already handled 2-step quantization above, and values less than 2
|
|
185
|
+
// are ignored because they don't make sense.
|
|
186
|
+
if (steps >= 3) {
|
|
187
|
+
percent = Math.round(percent * (steps - 1)) / (steps - 1);
|
|
188
|
+
}
|
|
189
|
+
// Interpolate the values
|
|
190
|
+
let h = (clockwiseDiff <= counterClockwiseDiff)
|
|
191
|
+
? loHSLUV.h + (clockwiseDiff * percent)
|
|
192
|
+
: loHSLUV.h - (counterClockwiseDiff * percent);
|
|
193
|
+
if (h < 0)
|
|
194
|
+
h = 360 + h;
|
|
195
|
+
if (h > 360)
|
|
196
|
+
h = h - 360;
|
|
197
|
+
let s = (1 - percent) * loHSLUV.s + percent * hiHSLUV.s;
|
|
198
|
+
let l = (1 - percent) * loHSLUV.l + percent * hiHSLUV.l;
|
|
199
|
+
let rgb = new HSLUV(h, s, l).toRGB();
|
|
200
|
+
return rgb.toHEX();
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
exports.Color = Color;
|
|
204
|
+
Color.EPSILON_SATURATION = 1.0;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export type DispatchTopic = string;
|
|
2
|
+
export type DispatchCallback = (topic: string, details?: any) => void;
|
|
3
|
+
export interface DispatchMessage {
|
|
4
|
+
topic: DispatchTopic;
|
|
5
|
+
details?: any;
|
|
6
|
+
}
|
|
7
|
+
export declare class Dispatch {
|
|
8
|
+
private static debug;
|
|
9
|
+
private static readonly callbacksByTopic;
|
|
10
|
+
static setDebug(value: boolean): void;
|
|
11
|
+
static subscribe(topic: string, callback: DispatchCallback): void;
|
|
12
|
+
static unsubscribe(topic: DispatchTopic, callback: DispatchCallback): void;
|
|
13
|
+
static publish(topic: DispatchTopic, details?: any): Promise<void>;
|
|
14
|
+
static sequence(messages: DispatchMessage[]): Promise<void>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Dispatch = void 0;
|
|
4
|
+
class Dispatch {
|
|
5
|
+
static setDebug(value) {
|
|
6
|
+
Dispatch.debug = value;
|
|
7
|
+
}
|
|
8
|
+
static subscribe(topic, callback) {
|
|
9
|
+
let topicCallbacks = [];
|
|
10
|
+
if (Dispatch.callbacksByTopic.has(topic)) {
|
|
11
|
+
topicCallbacks = Dispatch.callbacksByTopic.get(topic);
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
Dispatch.callbacksByTopic.set(topic, topicCallbacks);
|
|
15
|
+
}
|
|
16
|
+
topicCallbacks.push(callback);
|
|
17
|
+
}
|
|
18
|
+
static unsubscribe(topic, callback) {
|
|
19
|
+
if (Dispatch.callbacksByTopic.has(topic)) {
|
|
20
|
+
let topicCallbacks = [];
|
|
21
|
+
let newTopicCallbacks = [];
|
|
22
|
+
for (let i = 0, len = topicCallbacks.length; i < len; i++) {
|
|
23
|
+
let cb = topicCallbacks[i];
|
|
24
|
+
if (cb.toString() != callback.toString()) {
|
|
25
|
+
newTopicCallbacks.push(callback);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
if (newTopicCallbacks.length == 0) {
|
|
29
|
+
Dispatch.callbacksByTopic.delete(topic);
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
Dispatch.callbacksByTopic.set(topic, newTopicCallbacks);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
// Calls all the callbacks to this particular topic. Returns a Promise which resolves when ALL
|
|
37
|
+
// of the topic callbacks have also resolved, or in the same event loop if they are synchronous.
|
|
38
|
+
static async publish(topic, details) {
|
|
39
|
+
if (Dispatch.callbacksByTopic.has(topic)) {
|
|
40
|
+
let topicCallbackResults = [];
|
|
41
|
+
let errors = [];
|
|
42
|
+
let subjectSubscribers = Dispatch.callbacksByTopic.get(topic);
|
|
43
|
+
if (Dispatch.debug) {
|
|
44
|
+
console.log(`Dispatching '${topic}' to ${subjectSubscribers.length} subscribers, with details: ${JSON.stringify(details)}`);
|
|
45
|
+
}
|
|
46
|
+
for (let i = 0, len = subjectSubscribers.length; i < len; i++) {
|
|
47
|
+
let callback = subjectSubscribers[i];
|
|
48
|
+
// catch errors here so we don't interrupt any of the other callbacks
|
|
49
|
+
let result;
|
|
50
|
+
try {
|
|
51
|
+
result = callback(topic, details);
|
|
52
|
+
topicCallbackResults.push(result);
|
|
53
|
+
}
|
|
54
|
+
catch (e) {
|
|
55
|
+
errors.push(e);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
await Promise.all(topicCallbackResults);
|
|
59
|
+
if (errors.length > 0) {
|
|
60
|
+
return Promise.reject(errors);
|
|
61
|
+
}
|
|
62
|
+
return Promise.resolve();
|
|
63
|
+
}
|
|
64
|
+
else if (Dispatch.debug) {
|
|
65
|
+
console.log(`Dispatch has no subscribers to topic '${topic}'`);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
// Fire off a sequence of messages. Waits for the preceding message callbacks to finish / resolve
|
|
69
|
+
// before publishing the next (if the first message throws an exception, this short-circuits).
|
|
70
|
+
static async sequence(messages) {
|
|
71
|
+
for (let i = 0, len = messages.length; i < len; i++) {
|
|
72
|
+
let message = messages[i];
|
|
73
|
+
await Dispatch.publish(message.topic, message.details);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
exports.Dispatch = Dispatch;
|
|
78
|
+
Dispatch.debug = false;
|
|
79
|
+
Dispatch.callbacksByTopic = new Map();
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare class EditDistance {
|
|
2
|
+
private static readonly CHARACTERS;
|
|
3
|
+
private static readonly FORBIDDEN_START_AND_END_CHARS;
|
|
4
|
+
static readonly ALWAYS_TRUE: (word: string) => boolean;
|
|
5
|
+
static of(s1: string, s2: string): number;
|
|
6
|
+
static permute(word: string, distance: number, predicate?: (word: string) => boolean): string[];
|
|
7
|
+
private static preFilterCandidate;
|
|
8
|
+
private static generateDeleteCandidates;
|
|
9
|
+
private static generateTransposeCandidates;
|
|
10
|
+
private static generateReplaceCandidates;
|
|
11
|
+
private static generateInsertCandidates;
|
|
12
|
+
private static collectCandidateIfPassPredicate;
|
|
13
|
+
}
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EditDistance = void 0;
|
|
4
|
+
const Struct_1 = require("../util/Struct");
|
|
5
|
+
class EditDistance {
|
|
6
|
+
// This function copied from here:
|
|
7
|
+
// https://github.com/gustaveWPM/Typescript-Damerau-Levenshtein/blob/main/damerauLevenshtein.ts
|
|
8
|
+
// The algorithm is designed here:
|
|
9
|
+
// https://en.wikipedia.org/wiki/Damerau–Levenshtein_distance
|
|
10
|
+
static of(s1, s2) {
|
|
11
|
+
if (s1 === s2)
|
|
12
|
+
return 0;
|
|
13
|
+
const [s1len, s2len] = [s1.length, s2.length];
|
|
14
|
+
const matrix = Array.from({ length: s1len + 1 }, () => new Array(s2len + 1).fill(0));
|
|
15
|
+
for (let y = 1; y <= s1len; y++)
|
|
16
|
+
matrix[y][0] = y;
|
|
17
|
+
for (let x = 1; x <= s2len; x++)
|
|
18
|
+
matrix[0][x] = x;
|
|
19
|
+
for (let y = 1; y <= s1len; y++) {
|
|
20
|
+
for (let x = 1; x <= s2len; x++) {
|
|
21
|
+
if (s1[y - 1] === s2[x - 1]) {
|
|
22
|
+
matrix[y][x] = matrix[y - 1][x - 1];
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
matrix[y][x] =
|
|
26
|
+
1 +
|
|
27
|
+
Math.min(matrix[y - 1][x], matrix[y][x - 1], matrix[y - 1][x - 1]);
|
|
28
|
+
if (y > 1 &&
|
|
29
|
+
x > 1 &&
|
|
30
|
+
s1[y - 1] === s2[x - 2] &&
|
|
31
|
+
s1[y - 2] === s2[x - 1]) {
|
|
32
|
+
matrix[y][x] = Math.min(matrix[y][x], matrix[y - 2][x - 2] + 1);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return matrix[s1len][s2len];
|
|
38
|
+
}
|
|
39
|
+
static permute(word, distance, predicate) {
|
|
40
|
+
let roots = [word];
|
|
41
|
+
let predicateIsFunction = typeof (predicate) === "function";
|
|
42
|
+
let useDeferredPredicate = distance > 1 && predicateIsFunction;
|
|
43
|
+
let failed = {};
|
|
44
|
+
let candidates = {};
|
|
45
|
+
while (distance > 0) {
|
|
46
|
+
let p = distance > 1 || !predicateIsFunction
|
|
47
|
+
? EditDistance.ALWAYS_TRUE
|
|
48
|
+
: predicate;
|
|
49
|
+
let lastGenCandidates = Struct_1.Struct.clone(candidates);
|
|
50
|
+
for (let i = 0, len = roots.length; i < len; i++) {
|
|
51
|
+
word = roots[i];
|
|
52
|
+
let wordLength = word.length;
|
|
53
|
+
EditDistance.generateDeleteCandidates(failed, candidates, p, word, wordLength);
|
|
54
|
+
EditDistance.generateTransposeCandidates(failed, candidates, p, word, wordLength);
|
|
55
|
+
EditDistance.generateReplaceCandidates(failed, candidates, p, word, wordLength);
|
|
56
|
+
EditDistance.generateInsertCandidates(failed, candidates, p, word, wordLength);
|
|
57
|
+
}
|
|
58
|
+
distance--;
|
|
59
|
+
if (distance === 0) {
|
|
60
|
+
if (useDeferredPredicate) {
|
|
61
|
+
let confirmedCandidates = {};
|
|
62
|
+
for (let candidate in candidates) {
|
|
63
|
+
EditDistance.collectCandidateIfPassPredicate(failed, confirmedCandidates, candidate, predicate);
|
|
64
|
+
}
|
|
65
|
+
candidates = confirmedCandidates;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
roots = [];
|
|
70
|
+
for (let candidate in candidates) {
|
|
71
|
+
if (!lastGenCandidates.hasOwnProperty(candidate)) {
|
|
72
|
+
roots.push(candidate);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return Object.keys(candidates);
|
|
78
|
+
}
|
|
79
|
+
static preFilterCandidate(failed, candidates, candidate, predicate) {
|
|
80
|
+
const firstChar = candidate.charAt(0);
|
|
81
|
+
const lastChar = candidate.charAt(candidate.length - 1);
|
|
82
|
+
if (!EditDistance.FORBIDDEN_START_AND_END_CHARS.includes(firstChar) && !EditDistance.FORBIDDEN_START_AND_END_CHARS.includes(lastChar)) {
|
|
83
|
+
EditDistance.collectCandidateIfPassPredicate(failed, candidates, candidate, predicate);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
static generateDeleteCandidates(failed, candidates, predicate, word, len) {
|
|
87
|
+
if (len < 2) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
let last = len - 1;
|
|
91
|
+
for (let i = 0; i < len; i++) {
|
|
92
|
+
let candidate;
|
|
93
|
+
if (i === 0) {
|
|
94
|
+
candidate = word.substring(1);
|
|
95
|
+
}
|
|
96
|
+
else if (i === last) {
|
|
97
|
+
candidate = word.substring(0, last);
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
candidate = word.substring(0, i) + word.substring(i + 1, len);
|
|
101
|
+
}
|
|
102
|
+
EditDistance.preFilterCandidate(failed, candidates, candidate, predicate);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
static generateTransposeCandidates(failed, candidates, predicate, word, len) {
|
|
106
|
+
if (len < 2) {
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
let last = len - 1;
|
|
111
|
+
for (let i = 0; i < last; i++) {
|
|
112
|
+
let textBefore = i === 0 ? "" : word.substring(0, i);
|
|
113
|
+
let a = word.charAt(i);
|
|
114
|
+
let b = word.charAt(i + 1);
|
|
115
|
+
let textAfter = i === last - 1 ? "" : word.substring(i + 2);
|
|
116
|
+
const candidate = textBefore + b + a + textAfter;
|
|
117
|
+
EditDistance.preFilterCandidate(failed, candidates, candidate, predicate);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
static generateReplaceCandidates(failed, candidates, predicate, word, len) {
|
|
122
|
+
if (len < 2) {
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
let last = len - 1;
|
|
126
|
+
for (let i = 0; i < len; i++) {
|
|
127
|
+
let charToReplace = word.charAt(i);
|
|
128
|
+
for (let j = 0, jLen = EditDistance.CHARACTERS.length; j < jLen; j++) {
|
|
129
|
+
let c = EditDistance.CHARACTERS[j];
|
|
130
|
+
if (c !== charToReplace) {
|
|
131
|
+
let candidate;
|
|
132
|
+
if (i === 0) {
|
|
133
|
+
candidate = c + word.substring(1);
|
|
134
|
+
}
|
|
135
|
+
else if (i === last) {
|
|
136
|
+
candidate = word.substring(0, last) + c;
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
candidate = word.substring(0, i) + c + word.substring(i + 1, len);
|
|
140
|
+
}
|
|
141
|
+
EditDistance.preFilterCandidate(failed, candidates, candidate, predicate);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
static generateInsertCandidates(failed, candidates, predicate, word, len) {
|
|
147
|
+
for (let j = 0, jLen = EditDistance.CHARACTERS.length; j < jLen; j++) {
|
|
148
|
+
let c = EditDistance.CHARACTERS[j];
|
|
149
|
+
EditDistance.preFilterCandidate(failed, candidates, c + word, predicate);
|
|
150
|
+
for (let i = 1; i < len; i++) {
|
|
151
|
+
EditDistance.preFilterCandidate(failed, candidates, word.substring(0, i) + c + word.substring(i, len), predicate);
|
|
152
|
+
}
|
|
153
|
+
EditDistance.preFilterCandidate(failed, candidates, word + c, predicate);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
static collectCandidateIfPassPredicate(failed, candidates, candidate, predicate) {
|
|
157
|
+
// If this candidate has failed, don't bother checking it again.
|
|
158
|
+
if (failed.hasOwnProperty(candidate)) {
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
// If we've already collected this candidate, don't collect it again.
|
|
162
|
+
if (candidates.hasOwnProperty(candidate)) {
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
if (!predicate(candidate)) {
|
|
166
|
+
failed[candidate] = candidate;
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
candidates[candidate] = candidate;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
exports.EditDistance = EditDistance;
|
|
173
|
+
// This list of characters is used to generate candidates for the edit distance algorithm.
|
|
174
|
+
// These characters exclude numerals, punctuation, and most non-English characters. However,
|
|
175
|
+
// this list does include the characters çéñöü becuase they are common in English borrow-words
|
|
176
|
+
// like "façade", "café", "jalapeño", and "über". This list also includes the hyphen and
|
|
177
|
+
// apostrophe, which are common in English words. This list excludes characters that might
|
|
178
|
+
// be common in proper names from non-English cultures, like "á", "í", "ó", "ú", "ý", "ÿ",
|
|
179
|
+
// "â", "ê", "î", "ô", "û", so we will sometimes be unable to include those words in
|
|
180
|
+
// spelling suggestions.
|
|
181
|
+
EditDistance.CHARACTERS = "abcdefghijklmnopqrstuvwxyzçéñöü'-";
|
|
182
|
+
// We don't allow words to start or end with a hyphen or apostrophe.
|
|
183
|
+
EditDistance.FORBIDDEN_START_AND_END_CHARS = "-'";
|
|
184
|
+
EditDistance.ALWAYS_TRUE = function () { return true; };
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
export type LogLevel = 'error' | 'warn' | 'info' | 'debug';
|
|
2
|
+
export type ClientType = 'user' | 'server' | 'desktop' | 'browser';
|
|
3
|
+
export interface LogItem {
|
|
4
|
+
timestamp: string;
|
|
5
|
+
level: LogLevel;
|
|
6
|
+
message: string;
|
|
7
|
+
fields: LogFields;
|
|
8
|
+
}
|
|
9
|
+
export interface LogRecorder {
|
|
10
|
+
recordLogEntry(item: LogItem): void;
|
|
11
|
+
inspect(err: any): string;
|
|
12
|
+
}
|
|
13
|
+
export declare abstract class ConsoleJsonLogRecorder implements LogRecorder {
|
|
14
|
+
abstract inspect(err: any): string;
|
|
15
|
+
recordLogEntry(item: LogItem): void;
|
|
16
|
+
}
|
|
17
|
+
export declare class Logger {
|
|
18
|
+
private recorder;
|
|
19
|
+
private timestamp;
|
|
20
|
+
private level;
|
|
21
|
+
private message;
|
|
22
|
+
private fields;
|
|
23
|
+
constructor(recorder: LogRecorder);
|
|
24
|
+
static create(recorder: LogRecorder, context?: string): Logger;
|
|
25
|
+
clone(): Logger;
|
|
26
|
+
send(): void;
|
|
27
|
+
info(message: string): Logger;
|
|
28
|
+
warn(message: string): Logger;
|
|
29
|
+
debug(message: string): Logger;
|
|
30
|
+
error(message: string, err?: any): Logger;
|
|
31
|
+
withTimestamp(timestamp: Date | string): Logger;
|
|
32
|
+
withLevel(level: LogLevel): Logger;
|
|
33
|
+
withMessage(message: string): Logger;
|
|
34
|
+
withFields(fields: LogFields): Logger;
|
|
35
|
+
withField(key: string, value: string | number | boolean | Date): Logger;
|
|
36
|
+
withServiceName(serviceName: string): Logger;
|
|
37
|
+
withNodeName(nodeName: string): Logger;
|
|
38
|
+
withVersion(version: string): Logger;
|
|
39
|
+
withClientType(clientType: ClientType): Logger;
|
|
40
|
+
withClientServiceName(serviceName: string): Logger;
|
|
41
|
+
withClientNodeName(nodeName: string): Logger;
|
|
42
|
+
withClientVersion(version: string): Logger;
|
|
43
|
+
withTopic(topic: string): Logger;
|
|
44
|
+
withSubtopic(subtopic: string): Logger;
|
|
45
|
+
withName(name: string): Logger;
|
|
46
|
+
withContext(context: string): Logger;
|
|
47
|
+
withUsingJwt(usingJwt: boolean): Logger;
|
|
48
|
+
withUsingPassHash(usingPassHash: boolean): Logger;
|
|
49
|
+
withUserId(userId: string): Logger;
|
|
50
|
+
withEmail(email: string): Logger;
|
|
51
|
+
withUrl(url: string): Logger;
|
|
52
|
+
withSessionRef(sessionRef: string): Logger;
|
|
53
|
+
withContentKind(kind: string): Logger;
|
|
54
|
+
withContentRef(ref: string): Logger;
|
|
55
|
+
withCount(count: number): Logger;
|
|
56
|
+
withDurationMillis(duration: number): Logger;
|
|
57
|
+
withDocVersion(version: number): Logger;
|
|
58
|
+
withWordCount(count: number): Logger;
|
|
59
|
+
withBucket(bucket: string): Logger;
|
|
60
|
+
withFileName(fileName: string): Logger;
|
|
61
|
+
withFileSize(size: number): Logger;
|
|
62
|
+
withRequestBody(body: any): Logger;
|
|
63
|
+
clearParams(): Logger;
|
|
64
|
+
withParams(params: any): Logger;
|
|
65
|
+
withChangingData(originalData: any, transformedData: any): Logger;
|
|
66
|
+
withOriginalData(data: any): Logger;
|
|
67
|
+
withTransformedData(data: any): Logger;
|
|
68
|
+
withIgnoreConflict(ignoreConflict: boolean): Logger;
|
|
69
|
+
withError(err: any): Logger;
|
|
70
|
+
private static ensureStringified;
|
|
71
|
+
private static enforceFieldType;
|
|
72
|
+
private static makeTypeErrorMessage;
|
|
73
|
+
}
|
|
74
|
+
export interface LogFields {
|
|
75
|
+
service_name?: string;
|
|
76
|
+
node_name?: string;
|
|
77
|
+
version?: string;
|
|
78
|
+
client_type?: ClientType;
|
|
79
|
+
client_service_name?: string;
|
|
80
|
+
client_node_name?: string;
|
|
81
|
+
client_version?: string;
|
|
82
|
+
context?: string;
|
|
83
|
+
name?: string;
|
|
84
|
+
topic?: string;
|
|
85
|
+
subtopic?: string;
|
|
86
|
+
using_jwt?: boolean;
|
|
87
|
+
using_pass_hash?: boolean;
|
|
88
|
+
user_id?: string;
|
|
89
|
+
email?: string;
|
|
90
|
+
url?: string;
|
|
91
|
+
session_ref?: string;
|
|
92
|
+
content_kind?: string;
|
|
93
|
+
content_ref?: string;
|
|
94
|
+
doc_version?: number;
|
|
95
|
+
word_count?: number;
|
|
96
|
+
bucket?: string;
|
|
97
|
+
file_name?: string;
|
|
98
|
+
file_size?: number;
|
|
99
|
+
count?: number;
|
|
100
|
+
duration_millis?: number;
|
|
101
|
+
request_body?: string;
|
|
102
|
+
params?: string;
|
|
103
|
+
original_data?: string;
|
|
104
|
+
transformed_data?: string;
|
|
105
|
+
ignore_conflict?: boolean;
|
|
106
|
+
error_body?: string;
|
|
107
|
+
[key: string]: string | number | boolean;
|
|
108
|
+
}
|