@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,47 @@
|
|
|
1
|
+
export class Base62 {
|
|
2
|
+
|
|
3
|
+
public static readonly CHARS:string = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
|
4
|
+
|
|
5
|
+
public static encode(value:number, padToLength:number = 1):string {
|
|
6
|
+
if (value < 0) {
|
|
7
|
+
throw new Error("number out of range: " + value);
|
|
8
|
+
}
|
|
9
|
+
let result:string = "";
|
|
10
|
+
while (value > 0) {
|
|
11
|
+
let index:number = value % 62;
|
|
12
|
+
let digit:string = Base62.CHARS.charAt(index);
|
|
13
|
+
result = digit + result;
|
|
14
|
+
value = Math.floor(value / 62);
|
|
15
|
+
}
|
|
16
|
+
while (result.length < padToLength) {
|
|
17
|
+
result = "0" + result;
|
|
18
|
+
}
|
|
19
|
+
return result;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
public static decode(value:string) {
|
|
23
|
+
let result = 0;
|
|
24
|
+
for (let i:number = 0, len:number = value.length; i < len; i++) {
|
|
25
|
+
let c:string = value.charAt(i);
|
|
26
|
+
result *= 62;
|
|
27
|
+
result += Base62.CHARS.indexOf(c);
|
|
28
|
+
}
|
|
29
|
+
return result;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
public static fromHexHash(hex:string, length:number):string {
|
|
33
|
+
// NOTE: the crazy one-liner below is equivalent to this commented code...
|
|
34
|
+
// const b64 = Buffer.from(hex, 'hex').toString('base64');
|
|
35
|
+
// ...but it doesn't require Buffer class, which is only available in Node.js, not in browsers.
|
|
36
|
+
// This one-liner came from stackoverflow: https://stackoverflow.com/questions/23190056/hex-to-base64-converter-for-javascript
|
|
37
|
+
const b64 = btoa(hex.match(/\w{2}/g).map((a) => { return String.fromCharCode(parseInt(a, 16)) }).join(""));
|
|
38
|
+
let alphanum = b64.replace(/[^a-zA-Z0-9]/g, "");
|
|
39
|
+
if (alphanum.length < length) {
|
|
40
|
+
alphanum = alphanum.padEnd(length, "0");
|
|
41
|
+
} else if (alphanum.length > length) {
|
|
42
|
+
alphanum = alphanum.substring(0, length);
|
|
43
|
+
}
|
|
44
|
+
return alphanum;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import md5 from 'md5';
|
|
2
|
+
import { ContentId } from '../models/content/Content';
|
|
3
|
+
import { Base62 } from './Base62';
|
|
4
|
+
|
|
5
|
+
export class CachingHasher {
|
|
6
|
+
|
|
7
|
+
private static readonly MAX_SIZE:number = 1000;
|
|
8
|
+
|
|
9
|
+
private static md5HashLookup:Map<string, string> = new Map<string, string>();
|
|
10
|
+
private static contentIdLookup:Map<string, ContentId> = new Map<string, ContentId>();
|
|
11
|
+
|
|
12
|
+
public static makeMd5Hash(text:string):string {
|
|
13
|
+
if (CachingHasher.md5HashLookup.size > CachingHasher.MAX_SIZE) {
|
|
14
|
+
CachingHasher.md5HashLookup.clear();
|
|
15
|
+
}
|
|
16
|
+
if (CachingHasher.md5HashLookup.has(text)) {
|
|
17
|
+
return CachingHasher.md5HashLookup.get(text);
|
|
18
|
+
} else {
|
|
19
|
+
const rawHash = md5(text);
|
|
20
|
+
this.md5HashLookup.set(text, rawHash);
|
|
21
|
+
return rawHash;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
public static makeMd5ContentId(text:string):ContentId {
|
|
26
|
+
if (CachingHasher.contentIdLookup.size > CachingHasher.MAX_SIZE) {
|
|
27
|
+
CachingHasher.contentIdLookup.clear();
|
|
28
|
+
}
|
|
29
|
+
if (CachingHasher.contentIdLookup.has(text)) {
|
|
30
|
+
return CachingHasher.contentIdLookup.get(text);
|
|
31
|
+
} else {
|
|
32
|
+
const rawHash = md5(text);
|
|
33
|
+
const asBase62 = Base62.fromHexHash(rawHash, 16) as ContentId;
|
|
34
|
+
this.contentIdLookup.set(text, asBase62);
|
|
35
|
+
return asBase62;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
export type DispatchTopic = string;
|
|
2
|
+
export type DispatchCallback = (topic:string, details?:any) => void;
|
|
3
|
+
|
|
4
|
+
export interface DispatchMessage {
|
|
5
|
+
topic:DispatchTopic;
|
|
6
|
+
details?:any;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export class Dispatch {
|
|
10
|
+
|
|
11
|
+
private static debug:boolean = false;
|
|
12
|
+
|
|
13
|
+
private static readonly callbacksByTopic:Map<DispatchTopic, DispatchCallback[]> = new Map();
|
|
14
|
+
|
|
15
|
+
public static setDebug(value:boolean):void {
|
|
16
|
+
Dispatch.debug = value;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
public static subscribe(
|
|
20
|
+
topic:string,
|
|
21
|
+
callback:DispatchCallback
|
|
22
|
+
):void {
|
|
23
|
+
let topicCallbacks:DispatchCallback[] = [];
|
|
24
|
+
if (Dispatch.callbacksByTopic.has(topic)) {
|
|
25
|
+
topicCallbacks = Dispatch.callbacksByTopic.get(topic);
|
|
26
|
+
} else {
|
|
27
|
+
Dispatch.callbacksByTopic.set(topic, topicCallbacks);
|
|
28
|
+
}
|
|
29
|
+
topicCallbacks.push(callback);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
public static unsubscribe(
|
|
33
|
+
topic:DispatchTopic,
|
|
34
|
+
callback:DispatchCallback
|
|
35
|
+
) {
|
|
36
|
+
if (Dispatch.callbacksByTopic.has(topic)) {
|
|
37
|
+
let topicCallbacks:DispatchCallback[] = [];
|
|
38
|
+
let newTopicCallbacks = [];
|
|
39
|
+
for (let i = 0, len = topicCallbacks.length; i < len; i++) {
|
|
40
|
+
let cb = topicCallbacks[i];
|
|
41
|
+
if (cb.toString() != callback.toString()) {
|
|
42
|
+
newTopicCallbacks.push(callback);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
if (newTopicCallbacks.length == 0) {
|
|
46
|
+
Dispatch.callbacksByTopic.delete(topic);
|
|
47
|
+
} else {
|
|
48
|
+
Dispatch.callbacksByTopic.set(topic, newTopicCallbacks);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Calls all the callbacks to this particular topic. Returns a Promise which resolves when ALL
|
|
54
|
+
// of the topic callbacks have also resolved, or in the same event loop if they are synchronous.
|
|
55
|
+
public static async publish(topic:DispatchTopic, details?:any):Promise<void> {
|
|
56
|
+
if (Dispatch.callbacksByTopic.has(topic)) {
|
|
57
|
+
let topicCallbackResults = [];
|
|
58
|
+
let errors = [];
|
|
59
|
+
let subjectSubscribers = Dispatch.callbacksByTopic.get(topic);
|
|
60
|
+
if (Dispatch.debug) {
|
|
61
|
+
console.log(`Dispatching '${topic}' to ${subjectSubscribers.length} subscribers, with details: ${JSON.stringify(details)}`);
|
|
62
|
+
}
|
|
63
|
+
for (let i = 0, len = subjectSubscribers.length; i < len; i++) {
|
|
64
|
+
let callback = subjectSubscribers[i];
|
|
65
|
+
// catch errors here so we don't interrupt any of the other callbacks
|
|
66
|
+
let result;
|
|
67
|
+
try {
|
|
68
|
+
result = callback(topic, details);
|
|
69
|
+
topicCallbackResults.push(result);
|
|
70
|
+
} catch (e) {
|
|
71
|
+
errors.push(e);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
await Promise.all(topicCallbackResults);
|
|
75
|
+
if (errors.length > 0) {
|
|
76
|
+
return Promise.reject(errors);
|
|
77
|
+
}
|
|
78
|
+
return Promise.resolve();
|
|
79
|
+
} else if (Dispatch.debug) {
|
|
80
|
+
console.log(`Dispatch has no subscribers to topic '${topic}'`);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// Fire off a sequence of messages. Waits for the preceding message callbacks to finish / resolve
|
|
85
|
+
// before publishing the next (if the first message throws an exception, this short-circuits).
|
|
86
|
+
public static async sequence(messages:DispatchMessage[]):Promise<void> {
|
|
87
|
+
for (let i = 0, len = messages.length; i < len; i++) {
|
|
88
|
+
let message:DispatchMessage = messages[i];
|
|
89
|
+
await Dispatch.publish(message.topic, message.details);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|