@shaxpir/duiduidui-models 1.0.1 → 1.1.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/dist/models/{content/ArrayView.d.ts → ArrayView.d.ts} +1 -1
- package/dist/models/{content/ArrayView.js → ArrayView.js} +14 -14
- package/dist/models/BayesianScore.d.ts +9 -0
- package/dist/models/BayesianScore.js +27 -0
- package/dist/models/{markup/ChangeModel.d.ts → ChangeModel.d.ts} +2 -3
- package/dist/models/{markup/ChangeModel.js → ChangeModel.js} +20 -10
- package/dist/models/{content/Content.d.ts → Content.d.ts} +9 -10
- package/dist/models/{content/Content.js → Content.js} +2 -6
- package/dist/models/{content/ContentKind.d.ts → ContentKind.d.ts} +3 -0
- package/dist/models/{content/ContentKind.js → ContentKind.js} +5 -1
- package/dist/models/{content/Device.d.ts → Device.d.ts} +15 -7
- package/dist/models/{content/Device.js → Device.js} +14 -18
- package/dist/models/Hanzi.d.ts +15 -0
- package/dist/models/{content/Manifest.d.ts → Manifest.d.ts} +7 -3
- package/dist/models/{content/Manifest.js → Manifest.js} +12 -8
- package/dist/models/{content/Media.d.ts → Media.d.ts} +2 -3
- package/dist/models/{content/Media.js → Media.js} +4 -5
- package/dist/models/{content/Metric.d.ts → Metric.d.ts} +2 -3
- package/dist/models/{content/Metric.js → Metric.js} +18 -20
- package/dist/models/{content/Model.d.ts → Model.d.ts} +3 -5
- package/dist/models/{content/Model.js → Model.js} +5 -6
- package/dist/models/{markup/Operation.d.ts → Operation.d.ts} +2 -5
- package/dist/models/{markup/Operation.js → Operation.js} +30 -25
- package/dist/models/Phrase.d.ts +39 -0
- package/dist/models/{content/Profile.d.ts → Profile.d.ts} +1 -2
- package/dist/models/{content/Profile.js → Profile.js} +7 -9
- package/dist/models/Progress.d.ts +26 -0
- package/dist/models/Progress.js +39 -0
- package/dist/models/Review.d.ts +14 -0
- package/dist/models/{content/Session.d.ts → Session.d.ts} +7 -15
- package/dist/models/Session.js +103 -0
- package/dist/models/Term.d.ts +36 -0
- package/dist/models/Term.js +82 -0
- package/dist/models/User.d.ts +32 -0
- package/dist/models/User.js +65 -0
- package/dist/models/Workspace.d.ts +37 -0
- package/dist/models/Workspace.js +94 -0
- package/dist/models/index.d.ts +22 -2
- package/dist/models/index.js +22 -2
- package/dist/repo/PermissiveJson1.d.ts +16 -16
- package/dist/repo/PermissiveJson1.js +17 -7
- package/dist/repo/ShareSync.d.ts +6 -6
- package/dist/repo/ShareSync.js +26 -19
- package/dist/repo/index.d.ts +1 -0
- package/dist/repo/index.js +1 -0
- package/dist/util/index.d.ts +0 -6
- package/dist/util/index.js +0 -6
- package/lib/models/{content/ArrayView.ts → ArrayView.ts} +2 -2
- package/lib/models/BayesianScore.ts +32 -0
- package/lib/models/{markup/ChangeModel.ts → ChangeModel.ts} +3 -4
- package/lib/models/{content/Content.ts → Content.ts} +15 -18
- package/lib/models/{content/ContentKind.ts → ContentKind.ts} +6 -1
- package/lib/models/{content/Device.ts → Device.ts} +26 -22
- package/lib/models/Hanzi.ts +16 -0
- package/lib/models/{content/Manifest.ts → Manifest.ts} +15 -6
- package/lib/models/{content/Media.ts → Media.ts} +3 -4
- package/lib/models/Metric.ts +233 -0
- package/lib/models/{content/Model.ts → Model.ts} +4 -6
- package/lib/models/{markup/Operation.ts → Operation.ts} +6 -16
- package/lib/models/{content/Permissions.ts → Permissions.ts} +0 -2
- package/lib/models/Phrase.ts +53 -0
- package/lib/models/{content/Profile.ts → Profile.ts} +4 -6
- package/lib/models/Progress.ts +66 -0
- package/lib/models/Review.ts +18 -0
- package/lib/models/Session.ts +140 -0
- package/lib/models/Term.ts +139 -0
- package/lib/models/User.ts +97 -0
- package/lib/models/Workspace.ts +129 -0
- package/lib/models/index.ts +22 -2
- package/lib/repo/ShareSync.ts +9 -13
- package/lib/repo/index.ts +1 -0
- package/lib/util/index.ts +0 -6
- package/package.json +4 -15
- package/dist/models/OutboundMessage.d.ts +0 -18
- package/dist/models/OutboundMessage.js +0 -25
- package/dist/models/content/Activity.d.ts +0 -10
- package/dist/models/content/Billing.d.ts +0 -144
- package/dist/models/content/Billing.js +0 -418
- package/dist/models/content/Book.d.ts +0 -77
- package/dist/models/content/Book.js +0 -407
- package/dist/models/content/Category.d.ts +0 -16
- package/dist/models/content/Category.js +0 -20
- package/dist/models/content/Checkpointable.d.ts +0 -21
- package/dist/models/content/Checkpointable.js +0 -156
- package/dist/models/content/Comment.d.ts +0 -19
- package/dist/models/content/Comment.js +0 -53
- package/dist/models/content/ConceptArt.d.ts +0 -31
- package/dist/models/content/ConceptArt.js +0 -84
- package/dist/models/content/Context.d.ts +0 -28
- package/dist/models/content/Context.js +0 -162
- package/dist/models/content/DevEnv.d.ts +0 -5
- package/dist/models/content/DevEnv.js +0 -9
- package/dist/models/content/Dictionary.d.ts +0 -31
- package/dist/models/content/Dictionary.js +0 -5
- package/dist/models/content/DictionaryEntry.d.ts +0 -20
- package/dist/models/content/DictionaryEntry.js +0 -2
- package/dist/models/content/ElasticModel.d.ts +0 -149
- package/dist/models/content/ElasticModel.js +0 -179
- package/dist/models/content/Environment.d.ts +0 -61
- package/dist/models/content/Environment.js +0 -124
- package/dist/models/content/ExportOptions.d.ts +0 -64
- package/dist/models/content/ExportOptions.js +0 -213
- package/dist/models/content/Folder.d.ts +0 -16
- package/dist/models/content/Folder.js +0 -33
- package/dist/models/content/Fragment.d.ts +0 -54
- package/dist/models/content/Fragment.js +0 -181
- package/dist/models/content/Hanzi.d.ts +0 -21
- package/dist/models/content/HighlightRule.d.ts +0 -9
- package/dist/models/content/HighlightRule.js +0 -2
- package/dist/models/content/Migration.d.ts +0 -68
- package/dist/models/content/Migration.js +0 -155
- package/dist/models/content/Phrase.d.ts +0 -8
- package/dist/models/content/Placeholder.d.ts +0 -8
- package/dist/models/content/Placeholder.js +0 -36
- package/dist/models/content/RichText.d.ts +0 -58
- package/dist/models/content/RichText.js +0 -79
- package/dist/models/content/Session.js +0 -173
- package/dist/models/content/Speech.d.ts +0 -67
- package/dist/models/content/Speech.js +0 -97
- package/dist/models/content/Stub.d.ts +0 -24
- package/dist/models/content/Stub.js +0 -179
- package/dist/models/content/Time.d.ts +0 -56
- package/dist/models/content/Time.js +0 -295
- package/dist/models/content/User.d.ts +0 -36
- package/dist/models/content/User.js +0 -95
- package/dist/models/content/Workspace.d.ts +0 -71
- package/dist/models/content/Workspace.js +0 -237
- package/dist/models/content/index.d.ts +0 -17
- package/dist/models/content/index.js +0 -34
- package/dist/models/legacy/LegacyBodyFormat.d.ts +0 -9
- package/dist/models/legacy/LegacyBodyFormat.js +0 -2
- package/dist/models/legacy/LegacyComment.d.ts +0 -12
- package/dist/models/legacy/LegacyComment.js +0 -2
- package/dist/models/legacy/LegacyContent.d.ts +0 -53
- package/dist/models/legacy/LegacyContent.js +0 -55
- package/dist/models/legacy/LegacyConversion.d.ts +0 -55
- package/dist/models/legacy/LegacyConversion.js +0 -401
- package/dist/models/legacy/LegacyFragment.d.ts +0 -21
- package/dist/models/legacy/LegacyFragment.js +0 -2
- package/dist/models/legacy/LegacyLocator.d.ts +0 -8
- package/dist/models/legacy/LegacyLocator.js +0 -31
- package/dist/models/legacy/LegacyOutboundMessage.d.ts +0 -16
- package/dist/models/legacy/LegacyOutboundMessage.js +0 -13
- package/dist/models/legacy/LegacyPicture.d.ts +0 -14
- package/dist/models/legacy/LegacyPicture.js +0 -2
- package/dist/models/legacy/LegacyProfile.d.ts +0 -9
- package/dist/models/legacy/LegacyProfile.js +0 -2
- package/dist/models/legacy/LegacySession.d.ts +0 -41
- package/dist/models/legacy/LegacySession.js +0 -35
- package/dist/models/legacy/LegacyStory.d.ts +0 -23
- package/dist/models/legacy/LegacyStory.js +0 -2
- package/dist/models/legacy/LegacyStub.d.ts +0 -15
- package/dist/models/legacy/LegacyStub.js +0 -2
- package/dist/models/legacy/LegacyTransaction.d.ts +0 -14
- package/dist/models/legacy/LegacyTransaction.js +0 -49
- package/dist/models/legacy/LegacyUser.d.ts +0 -28
- package/dist/models/legacy/LegacyUser.js +0 -32
- package/dist/models/legacy/LegacyWorkspace.d.ts +0 -23
- package/dist/models/legacy/LegacyWorkspace.js +0 -6
- package/dist/models/legacy/index.d.ts +0 -15
- package/dist/models/legacy/index.js +0 -32
- package/dist/models/markup/BodyFormat.d.ts +0 -14
- package/dist/models/markup/BodyFormat.js +0 -190
- package/dist/models/markup/DeltaOps.d.ts +0 -5
- package/dist/models/markup/DeltaOps.js +0 -74
- package/dist/models/markup/HtmlMarkup.d.ts +0 -4
- package/dist/models/markup/HtmlMarkup.js +0 -21
- package/dist/models/markup/index.d.ts +0 -4
- package/dist/models/markup/index.js +0 -21
- package/dist/util/Async.d.ts +0 -8
- package/dist/util/Async.js +0 -18
- package/dist/util/Base62.d.ts +0 -6
- package/dist/util/Base62.js +0 -47
- package/dist/util/BinarySearch.d.ts +0 -7
- package/dist/util/BinarySearch.js +0 -46
- package/dist/util/CachingHasher.d.ts +0 -8
- package/dist/util/CachingHasher.js +0 -41
- package/dist/util/Color.d.ts +0 -32
- package/dist/util/Color.js +0 -204
- package/dist/util/Dispatch.d.ts +0 -15
- package/dist/util/Dispatch.js +0 -79
- package/dist/util/EditDistance.d.ts +0 -13
- package/dist/util/EditDistance.js +0 -184
- package/dist/util/NumberFormat.d.ts +0 -14
- package/dist/util/NumberFormat.js +0 -224
- package/dist/util/Struct.d.ts +0 -4
- package/dist/util/Struct.js +0 -15
- package/dist/util/Template.d.ts +0 -16
- package/dist/util/Template.js +0 -128
- package/dist/util/Text.d.ts +0 -45
- package/dist/util/Text.js +0 -243
- package/dist/util/Tuples.d.ts +0 -9
- package/dist/util/Tuples.js +0 -135
- package/dist/util/Validate.d.ts +0 -4
- package/dist/util/Validate.js +0 -11
- package/dist/util/Vocabulary.d.ts +0 -3
- package/dist/util/Vocabulary.js +0 -35
- package/lib/models/content/Billing.ts +0 -558
- package/lib/models/content/DevEnv.ts +0 -5
- package/lib/models/content/DictionaryEntry.ts +0 -22
- package/lib/models/content/Hanzi.ts +0 -25
- package/lib/models/content/Phrase.ts +0 -10
- package/lib/models/content/Time.ts +0 -328
- package/lib/models/content/User.ts +0 -130
- package/lib/models/content/index.ts +0 -19
- package/lib/models/markup/DeltaOps.ts +0 -71
- package/lib/models/markup/index.ts +0 -6
- package/lib/util/Base62.ts +0 -47
- package/lib/util/CachingHasher.ts +0 -38
- package/lib/util/Dispatch.ts +0 -92
- package/lib/util/NumberFormat.ts +0 -194
- package/lib/util/Struct.ts +0 -14
- package/lib/util/Tuples.ts +0 -131
- /package/dist/models/{content/GeoLocation.d.ts → GeoLocation.d.ts} +0 -0
- /package/dist/models/{content/GeoLocation.js → GeoLocation.js} +0 -0
- /package/dist/models/{content/Hanzi.js → Hanzi.js} +0 -0
- /package/dist/models/{content/Permissions.d.ts → Permissions.d.ts} +0 -0
- /package/dist/models/{content/Permissions.js → Permissions.js} +0 -0
- /package/dist/models/{content/Phrase.js → Phrase.js} +0 -0
- /package/dist/models/{content/Activity.js → Review.js} +0 -0
- /package/dist/{models/markup → repo}/TextEditOps.d.ts +0 -0
- /package/dist/{models/markup → repo}/TextEditOps.js +0 -0
- /package/lib/models/{content/GeoLocation.ts → GeoLocation.ts} +0 -0
- /package/lib/{models/markup → repo}/TextEditOps.ts +0 -0
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Term = void 0;
|
|
4
|
+
const shaxpir_common_1 = require("@shaxpir/shaxpir-common");
|
|
5
|
+
const Content_1 = require("./Content");
|
|
6
|
+
const ContentKind_1 = require("./ContentKind");
|
|
7
|
+
const repo_1 = require("../repo");
|
|
8
|
+
class Term extends Content_1.Content {
|
|
9
|
+
static makeTermId(userId, text, senseRank) {
|
|
10
|
+
return shaxpir_common_1.CachingHasher.makeMd5Base62Hash(`${ContentKind_1.ContentKind.TERM}-${userId}-${text}-${senseRank}`);
|
|
11
|
+
}
|
|
12
|
+
static forUserPhrase(userId, phrase) {
|
|
13
|
+
const now = shaxpir_common_1.MultiClock.now();
|
|
14
|
+
const termId = shaxpir_common_1.CachingHasher.makeMd5Base62Hash(`${userId}-${phrase.text}-${phrase.sense_rank}`);
|
|
15
|
+
const initalAlpha = phrase.learn_rank < 100 ? 1 : 2;
|
|
16
|
+
const initalBeta = phrase.learn_rank < 100 ? 1 : 2;
|
|
17
|
+
return repo_1.ShareSyncFactory.get().createContent({
|
|
18
|
+
meta: {
|
|
19
|
+
ref: termId,
|
|
20
|
+
kind: ContentKind_1.ContentKind.TERM,
|
|
21
|
+
id: termId,
|
|
22
|
+
owner: userId,
|
|
23
|
+
created_at: now,
|
|
24
|
+
updated_at: now
|
|
25
|
+
},
|
|
26
|
+
payload: {
|
|
27
|
+
phrase_id: null,
|
|
28
|
+
text: phrase.text,
|
|
29
|
+
sense_rank: phrase.sense_rank,
|
|
30
|
+
hanzi_count: phrase.hanzi_count,
|
|
31
|
+
learn_rank: phrase.learn_rank,
|
|
32
|
+
pinyin: phrase.pinyin,
|
|
33
|
+
pinyin_tokenized: phrase.pinyin_tokenized,
|
|
34
|
+
transliteration: phrase.transliteration,
|
|
35
|
+
translation: phrase.translation,
|
|
36
|
+
notes: phrase.notes,
|
|
37
|
+
examples: phrase.examples,
|
|
38
|
+
keywords: phrase.keywords,
|
|
39
|
+
tags: phrase.tags,
|
|
40
|
+
starred_at: null,
|
|
41
|
+
alpha: 1,
|
|
42
|
+
beta: 1,
|
|
43
|
+
theta: 0.5,
|
|
44
|
+
reviews: []
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
static forBuiltinPhrase(userId, phrase) {
|
|
49
|
+
const now = shaxpir_common_1.MultiClock.now();
|
|
50
|
+
const termId = shaxpir_common_1.CachingHasher.makeMd5Base62Hash(`${userId}-${phrase.text}-${phrase.sense_rank}`);
|
|
51
|
+
return repo_1.ShareSyncFactory.get().createContent({
|
|
52
|
+
meta: {
|
|
53
|
+
ref: termId,
|
|
54
|
+
kind: ContentKind_1.ContentKind.TERM,
|
|
55
|
+
id: termId,
|
|
56
|
+
owner: userId,
|
|
57
|
+
created_at: now,
|
|
58
|
+
updated_at: now
|
|
59
|
+
},
|
|
60
|
+
payload: {
|
|
61
|
+
text: phrase.text,
|
|
62
|
+
sense_rank: phrase.sense_rank,
|
|
63
|
+
learn_rank: phrase.learn_rank,
|
|
64
|
+
phrase_id: phrase.id,
|
|
65
|
+
starred_at: null,
|
|
66
|
+
tags: [],
|
|
67
|
+
alpha: 1,
|
|
68
|
+
beta: 1,
|
|
69
|
+
theta: 0.5,
|
|
70
|
+
reviews: []
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
constructor(doc, shouldAcquire, shareSync) {
|
|
75
|
+
super(doc, shouldAcquire, shareSync);
|
|
76
|
+
}
|
|
77
|
+
get payload() {
|
|
78
|
+
this.checkDisposed("Term.payload");
|
|
79
|
+
return this.doc.data.payload;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
exports.Term = Term;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Doc } from '@shaxpir/sharedb/lib/client';
|
|
2
|
+
import { CompactDateTime, MultiTime } from '@shaxpir/shaxpir-common';
|
|
3
|
+
import { ArrayView } from './ArrayView';
|
|
4
|
+
import { Content, ContentId, ContentMeta } from "./Content";
|
|
5
|
+
import { ShareSync } from '../repo';
|
|
6
|
+
export interface VerifiablePhone {
|
|
7
|
+
phone: string;
|
|
8
|
+
verified_at: CompactDateTime;
|
|
9
|
+
}
|
|
10
|
+
export interface VerifiableEmail {
|
|
11
|
+
email: string;
|
|
12
|
+
verified_at: CompactDateTime;
|
|
13
|
+
}
|
|
14
|
+
export interface UserPayload {
|
|
15
|
+
emails: VerifiableEmail[];
|
|
16
|
+
phones: VerifiablePhone[];
|
|
17
|
+
}
|
|
18
|
+
export interface UserBody {
|
|
19
|
+
meta: ContentMeta;
|
|
20
|
+
payload: UserPayload;
|
|
21
|
+
}
|
|
22
|
+
export declare class User extends Content {
|
|
23
|
+
private _emails;
|
|
24
|
+
private _phones;
|
|
25
|
+
constructor(doc: Doc, shouldAcquire: boolean, shareSync: ShareSync);
|
|
26
|
+
get payload(): UserPayload;
|
|
27
|
+
static create(userId: ContentId, payload: UserPayload, createdAt?: MultiTime): User;
|
|
28
|
+
get emails(): ArrayView<VerifiableEmail>;
|
|
29
|
+
get phones(): ArrayView<VerifiablePhone>;
|
|
30
|
+
verifyEmail(email: string, time: CompactDateTime): void;
|
|
31
|
+
verifyPhone(phone: string, time: CompactDateTime): void;
|
|
32
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.User = void 0;
|
|
4
|
+
const shaxpir_common_1 = require("@shaxpir/shaxpir-common");
|
|
5
|
+
const ArrayView_1 = require("./ArrayView");
|
|
6
|
+
const Content_1 = require("./Content");
|
|
7
|
+
const ContentKind_1 = require("./ContentKind");
|
|
8
|
+
const Operation_1 = require("./Operation");
|
|
9
|
+
const repo_1 = require("../repo");
|
|
10
|
+
class User extends Content_1.Content {
|
|
11
|
+
constructor(doc, shouldAcquire, shareSync) {
|
|
12
|
+
super(doc, shouldAcquire, shareSync);
|
|
13
|
+
this._emails = new ArrayView_1.ArrayView(this, ['payload', 'emails']);
|
|
14
|
+
this._phones = new ArrayView_1.ArrayView(this, ['payload', 'phones']);
|
|
15
|
+
}
|
|
16
|
+
get payload() {
|
|
17
|
+
return this.doc.data.payload;
|
|
18
|
+
}
|
|
19
|
+
static create(userId, payload, createdAt) {
|
|
20
|
+
// User creation always happens in UTC time
|
|
21
|
+
const now = shaxpir_common_1.MultiClock.utcNow();
|
|
22
|
+
// If the createdAt time is not provided, use the current time
|
|
23
|
+
createdAt ??= now;
|
|
24
|
+
return repo_1.ShareSyncFactory.get().createContent({
|
|
25
|
+
meta: {
|
|
26
|
+
ref: userId,
|
|
27
|
+
kind: ContentKind_1.ContentKind.USER,
|
|
28
|
+
id: userId,
|
|
29
|
+
owner: userId,
|
|
30
|
+
created_at: createdAt,
|
|
31
|
+
updated_at: now
|
|
32
|
+
},
|
|
33
|
+
payload: payload
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
get emails() {
|
|
37
|
+
return this._emails;
|
|
38
|
+
}
|
|
39
|
+
get phones() {
|
|
40
|
+
return this._phones;
|
|
41
|
+
}
|
|
42
|
+
verifyEmail(email, time) {
|
|
43
|
+
const idx = this._emails.firstIndexWhere(e => e.email === email);
|
|
44
|
+
if (idx >= 0 && this._emails.get(idx).verified_at !== time) {
|
|
45
|
+
const batch = new Operation_1.BatchOperation(this);
|
|
46
|
+
batch.setPathValue(['payload', 'emails', idx, 'verified_at'], time);
|
|
47
|
+
batch.commit();
|
|
48
|
+
}
|
|
49
|
+
else if (idx < 0) {
|
|
50
|
+
this._emails.push({ email, verified_at: time });
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
verifyPhone(phone, time) {
|
|
54
|
+
const idx = this._phones.firstIndexWhere(p => p.phone === phone);
|
|
55
|
+
if (idx >= 0 && this._phones.get(idx).verified_at !== time) {
|
|
56
|
+
const batch = new Operation_1.BatchOperation(this);
|
|
57
|
+
batch.setPathValue(['payload', 'phones', idx, 'verified_at'], time);
|
|
58
|
+
batch.commit();
|
|
59
|
+
}
|
|
60
|
+
else if (idx < 0) {
|
|
61
|
+
this._phones.push({ phone, verified_at: time });
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
exports.User = User;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Doc } from '@shaxpir/sharedb/lib/client';
|
|
2
|
+
import { CompactDate, CompactDateTime, MultiTime } from "@shaxpir/shaxpir-common";
|
|
3
|
+
import { ShareSync } from '../repo';
|
|
4
|
+
import { ArrayView } from './ArrayView';
|
|
5
|
+
import { Content, ContentBody, ContentId, ContentMeta } from "./Content";
|
|
6
|
+
import { TagFilterConfig } from './Device';
|
|
7
|
+
import { Session } from './Session';
|
|
8
|
+
export interface JourneyEntry {
|
|
9
|
+
key: string;
|
|
10
|
+
at_utc_time: CompactDateTime;
|
|
11
|
+
}
|
|
12
|
+
export interface WorkspacePayload {
|
|
13
|
+
devices: ContentId[];
|
|
14
|
+
sessions: MultiTime[];
|
|
15
|
+
journey?: {
|
|
16
|
+
[key: string]: CompactDateTime;
|
|
17
|
+
};
|
|
18
|
+
global_tags?: TagFilterConfig;
|
|
19
|
+
}
|
|
20
|
+
export interface WorkspaceBody extends ContentBody {
|
|
21
|
+
meta: ContentMeta;
|
|
22
|
+
payload: WorkspacePayload;
|
|
23
|
+
}
|
|
24
|
+
export declare class Workspace extends Content {
|
|
25
|
+
private _devicesView;
|
|
26
|
+
private _sessionsView;
|
|
27
|
+
constructor(doc: Doc, shouldAcquire: boolean, shareSync: ShareSync);
|
|
28
|
+
get payload(): WorkspacePayload;
|
|
29
|
+
static makeWorkspaceId(userId: ContentId): ContentId;
|
|
30
|
+
static create(userId: ContentId, deviceId: ContentId): Workspace;
|
|
31
|
+
get sessions(): ArrayView<MultiTime>;
|
|
32
|
+
get devices(): ArrayView<ContentId>;
|
|
33
|
+
acquireSessionsFromDate(sessionId: ContentId, localDate: CompactDate): Promise<Session[]>;
|
|
34
|
+
hasJourneyDate(journeyKey: string): boolean;
|
|
35
|
+
getJourneyDate(journeyKey: string): CompactDateTime;
|
|
36
|
+
setJourneyDate(journeyKey: string, journeyDate: CompactDateTime): void;
|
|
37
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Workspace = void 0;
|
|
4
|
+
const shaxpir_common_1 = require("@shaxpir/shaxpir-common");
|
|
5
|
+
const repo_1 = require("../repo");
|
|
6
|
+
const ArrayView_1 = require("./ArrayView");
|
|
7
|
+
const Content_1 = require("./Content");
|
|
8
|
+
const ContentKind_1 = require("./ContentKind");
|
|
9
|
+
const Operation_1 = require("./Operation");
|
|
10
|
+
const Session_1 = require("./Session");
|
|
11
|
+
class Workspace extends Content_1.Content {
|
|
12
|
+
constructor(doc, shouldAcquire, shareSync) {
|
|
13
|
+
super(doc, shouldAcquire, shareSync);
|
|
14
|
+
this._devicesView = new ArrayView_1.ArrayView(this, ['payload', 'devices']);
|
|
15
|
+
this._sessionsView = new ArrayView_1.ArrayView(this, ['payload', 'sessions']);
|
|
16
|
+
}
|
|
17
|
+
get payload() {
|
|
18
|
+
return this.doc.data.payload;
|
|
19
|
+
}
|
|
20
|
+
static makeWorkspaceId(userId) {
|
|
21
|
+
return shaxpir_common_1.CachingHasher.makeMd5Base62Hash(userId + "-" + ContentKind_1.ContentKind.WORKSPACE);
|
|
22
|
+
}
|
|
23
|
+
static create(userId, deviceId) {
|
|
24
|
+
const now = shaxpir_common_1.MultiClock.now();
|
|
25
|
+
const workspaceId = Workspace.makeWorkspaceId(userId);
|
|
26
|
+
return repo_1.ShareSyncFactory.get().createContent({
|
|
27
|
+
meta: {
|
|
28
|
+
ref: workspaceId,
|
|
29
|
+
kind: ContentKind_1.ContentKind.WORKSPACE,
|
|
30
|
+
id: workspaceId,
|
|
31
|
+
owner: userId,
|
|
32
|
+
created_at: now,
|
|
33
|
+
updated_at: now
|
|
34
|
+
},
|
|
35
|
+
payload: {
|
|
36
|
+
devices: [deviceId],
|
|
37
|
+
journey: {},
|
|
38
|
+
sessions: []
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
get sessions() {
|
|
43
|
+
this.checkDisposed("Workspace.sessions");
|
|
44
|
+
return this._sessionsView;
|
|
45
|
+
}
|
|
46
|
+
// NOTE: As the user adds devices, we will always add new devices to the end of the array.
|
|
47
|
+
// So the most-recently-added device will always be at the end.
|
|
48
|
+
get devices() {
|
|
49
|
+
this.checkDisposed("Workspace.devices");
|
|
50
|
+
return this._devicesView;
|
|
51
|
+
}
|
|
52
|
+
async acquireSessionsFromDate(sessionId, localDate) {
|
|
53
|
+
this.checkDisposed("Workspace.loadSessionsFromDate");
|
|
54
|
+
const shareSync = repo_1.ShareSyncFactory.get();
|
|
55
|
+
const sessions = [];
|
|
56
|
+
for (let i = 0, len = this.sessions.length; i < len; i++) {
|
|
57
|
+
const sessionCreatedAt = this.sessions.get(i);
|
|
58
|
+
const sessionCreatedLocalDate = shaxpir_common_1.Time.dateFrom(sessionCreatedAt.local_time);
|
|
59
|
+
if (localDate == sessionCreatedLocalDate) {
|
|
60
|
+
const sessionRef = Session_1.Session.makeSessionRef(sessionId, sessionCreatedAt);
|
|
61
|
+
const session = await shareSync.acquire(ContentKind_1.ContentKind.SESSION, sessionRef);
|
|
62
|
+
sessions.push(session);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return sessions;
|
|
66
|
+
}
|
|
67
|
+
hasJourneyDate(journeyKey) {
|
|
68
|
+
this.checkDisposed("Workspace.hasJourneyDate");
|
|
69
|
+
return this.payload.hasOwnProperty('journey') && this.payload.journey.hasOwnProperty(journeyKey);
|
|
70
|
+
}
|
|
71
|
+
getJourneyDate(journeyKey) {
|
|
72
|
+
this.checkDisposed("Workspace.getJourneyDate");
|
|
73
|
+
if (this.payload.hasOwnProperty('journey')) {
|
|
74
|
+
if (this.payload.journey.hasOwnProperty(journeyKey)) {
|
|
75
|
+
return this.payload.journey[journeyKey];
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
setJourneyDate(journeyKey, journeyDate) {
|
|
81
|
+
this.checkDisposed("Workspace.setJourneyDate");
|
|
82
|
+
const batch = new Operation_1.BatchOperation(this);
|
|
83
|
+
if (this.payload.hasOwnProperty('journey')) {
|
|
84
|
+
batch.setPathValue(['payload', 'journey', journeyKey], journeyDate);
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
const journey = {};
|
|
88
|
+
journey[journeyKey] = journeyDate;
|
|
89
|
+
batch.setPathValue(['payload', 'journey'], journey);
|
|
90
|
+
}
|
|
91
|
+
batch.commit();
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
exports.Workspace = Workspace;
|
package/dist/models/index.d.ts
CHANGED
|
@@ -1,2 +1,22 @@
|
|
|
1
|
-
export * from './
|
|
2
|
-
export * from './
|
|
1
|
+
export * from './ArrayView';
|
|
2
|
+
export * from './BayesianScore';
|
|
3
|
+
export * from './ChangeModel';
|
|
4
|
+
export * from './Content';
|
|
5
|
+
export * from './ContentKind';
|
|
6
|
+
export * from './Device';
|
|
7
|
+
export * from './GeoLocation';
|
|
8
|
+
export * from './Hanzi';
|
|
9
|
+
export * from './Manifest';
|
|
10
|
+
export * from './Media';
|
|
11
|
+
export * from './Metric';
|
|
12
|
+
export * from './Model';
|
|
13
|
+
export * from './Operation';
|
|
14
|
+
export * from './Permissions';
|
|
15
|
+
export * from './Phrase';
|
|
16
|
+
export * from './Profile';
|
|
17
|
+
export * from './Progress';
|
|
18
|
+
export * from './Review';
|
|
19
|
+
export * from './Session';
|
|
20
|
+
export * from './Term';
|
|
21
|
+
export * from './User';
|
|
22
|
+
export * from './Workspace';
|
package/dist/models/index.js
CHANGED
|
@@ -15,5 +15,25 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
16
16
|
};
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
__exportStar(require("./
|
|
19
|
-
__exportStar(require("./
|
|
18
|
+
__exportStar(require("./ArrayView"), exports);
|
|
19
|
+
__exportStar(require("./BayesianScore"), exports);
|
|
20
|
+
__exportStar(require("./ChangeModel"), exports);
|
|
21
|
+
__exportStar(require("./Content"), exports);
|
|
22
|
+
__exportStar(require("./ContentKind"), exports);
|
|
23
|
+
__exportStar(require("./Device"), exports);
|
|
24
|
+
__exportStar(require("./GeoLocation"), exports);
|
|
25
|
+
__exportStar(require("./Hanzi"), exports);
|
|
26
|
+
__exportStar(require("./Manifest"), exports);
|
|
27
|
+
__exportStar(require("./Media"), exports);
|
|
28
|
+
__exportStar(require("./Metric"), exports);
|
|
29
|
+
__exportStar(require("./Model"), exports);
|
|
30
|
+
__exportStar(require("./Operation"), exports);
|
|
31
|
+
__exportStar(require("./Permissions"), exports);
|
|
32
|
+
__exportStar(require("./Phrase"), exports);
|
|
33
|
+
__exportStar(require("./Profile"), exports);
|
|
34
|
+
__exportStar(require("./Progress"), exports);
|
|
35
|
+
__exportStar(require("./Review"), exports);
|
|
36
|
+
__exportStar(require("./Session"), exports);
|
|
37
|
+
__exportStar(require("./Term"), exports);
|
|
38
|
+
__exportStar(require("./User"), exports);
|
|
39
|
+
__exportStar(require("./Workspace"), exports);
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import * as Json1 from 'ot-json1';
|
|
2
2
|
export * from 'ot-json1';
|
|
3
3
|
export declare const type: {
|
|
4
|
-
transform(op1: Json1.
|
|
4
|
+
transform(op1: Json1.JSONOp, op2: Json1.JSONOp, side: "left" | "right"): Json1.JSONOp;
|
|
5
5
|
name: string;
|
|
6
6
|
uri: string;
|
|
7
|
-
readCursor: (op: Json1.
|
|
7
|
+
readCursor: (op: Json1.JSONOp) => Json1.ReadCursor;
|
|
8
8
|
writeCursor: () => Json1.WriteCursor;
|
|
9
9
|
create(data: Json1.Doc): Json1.Doc;
|
|
10
|
-
isNoop(op: Json1.
|
|
10
|
+
isNoop(op: Json1.JSONOp): boolean;
|
|
11
11
|
setDebug(val: boolean): void;
|
|
12
12
|
registerSubtype: (subtype: {
|
|
13
13
|
[k: string]: any;
|
|
@@ -20,7 +20,6 @@ export declare const type: {
|
|
|
20
20
|
invert?: (op: any) => any;
|
|
21
21
|
makeInvertible?: (op: any, doc: any) => any;
|
|
22
22
|
} | {
|
|
23
|
-
[k: string]: any;
|
|
24
23
|
type: {
|
|
25
24
|
[k: string]: any;
|
|
26
25
|
name: string;
|
|
@@ -32,27 +31,28 @@ export declare const type: {
|
|
|
32
31
|
invert?: (op: any) => any;
|
|
33
32
|
makeInvertible?: (op: any, doc: any) => any;
|
|
34
33
|
};
|
|
34
|
+
[k: string]: any;
|
|
35
35
|
}) => void;
|
|
36
|
-
checkValidOp: (op: Json1.
|
|
37
|
-
normalize: (op: Json1.
|
|
38
|
-
apply: (snapshot: Json1.Doc, op: Json1.
|
|
36
|
+
checkValidOp: (op: Json1.JSONOp) => void;
|
|
37
|
+
normalize: (op: Json1.JSONOp) => Json1.JSONOp;
|
|
38
|
+
apply: (snapshot: Json1.Doc | undefined, op: Json1.JSONOp) => string | number | boolean | Json1.Doc[] | {
|
|
39
39
|
[k: string]: Json1.Doc;
|
|
40
|
-
} |
|
|
41
|
-
transformPosition: (path: Json1.Path, op: Json1.
|
|
42
|
-
compose: (op1: Json1.
|
|
43
|
-
tryTransform: (op1: Json1.
|
|
40
|
+
} | null | undefined;
|
|
41
|
+
transformPosition: (path: Json1.Path, op: Json1.JSONOp) => Json1.Path | null;
|
|
42
|
+
compose: (op1: Json1.JSONOp, op2: Json1.JSONOp) => Json1.JSONOp;
|
|
43
|
+
tryTransform: (op1: Json1.JSONOp, op2: Json1.JSONOp, direction: "left" | "right") => {
|
|
44
44
|
ok: true;
|
|
45
|
-
result: Json1.
|
|
45
|
+
result: Json1.JSONOp;
|
|
46
46
|
} | {
|
|
47
47
|
ok: false;
|
|
48
48
|
conflict: Json1.Conflict;
|
|
49
49
|
};
|
|
50
|
-
makeInvertible: (op: Json1.
|
|
51
|
-
invert: (op: Json1.
|
|
52
|
-
invertWithDoc: (op: Json1.
|
|
50
|
+
makeInvertible: (op: Json1.JSONOp, doc: Json1.Doc) => Json1.JSONOp;
|
|
51
|
+
invert: (op: Json1.JSONOp) => Json1.JSONOp;
|
|
52
|
+
invertWithDoc: (op: Json1.JSONOp, doc: Json1.Doc) => Json1.JSONOp;
|
|
53
53
|
RM_UNEXPECTED_CONTENT: Json1.ConflictType;
|
|
54
54
|
DROP_COLLISION: Json1.ConflictType;
|
|
55
55
|
BLACKHOLE: Json1.ConflictType;
|
|
56
|
-
transformNoConflict: (op1: Json1.
|
|
56
|
+
transformNoConflict: (op1: Json1.JSONOp, op2: Json1.JSONOp, side: "left" | "right") => Json1.JSONOp;
|
|
57
57
|
typeAllowingConflictsPred: any;
|
|
58
58
|
};
|
|
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
15
|
}) : function(o, v) {
|
|
16
16
|
o["default"] = v;
|
|
17
17
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
25
35
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
26
36
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
27
37
|
};
|
package/dist/repo/ShareSync.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { ConnectionListener } from './ConnectionListener';
|
|
1
|
+
import { CompactDateTime } from '@shaxpir/shaxpir-common';
|
|
2
|
+
import { Model } from '../models';
|
|
3
|
+
import { Content, ContentBody, ContentId, ContentRef } from '../models/Content';
|
|
4
|
+
import { ContentKind } from '../models/ContentKind';
|
|
5
|
+
import { Manifest, ManifestBody } from '../models/Manifest';
|
|
7
6
|
import { Encryption } from '../util/Encryption';
|
|
7
|
+
import { ConnectionListener } from './ConnectionListener';
|
|
8
8
|
export declare enum ShareSyncDisposalStrategy {
|
|
9
9
|
UNSUBSCRIBE = 0,
|
|
10
10
|
DESTROY = 1,
|
package/dist/repo/ShareSync.js
CHANGED
|
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
15
|
}) : function(o, v) {
|
|
16
16
|
o["default"] = v;
|
|
17
17
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
25
35
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
37
|
};
|
|
@@ -29,13 +39,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
29
39
|
exports.ShareSync = exports.ShareSyncFactory = exports.ShareSyncDisposalStrategy = void 0;
|
|
30
40
|
const client_1 = __importStar(require("@shaxpir/sharedb/lib/client"));
|
|
31
41
|
const reconnecting_websocket_1 = __importDefault(require("reconnecting-websocket"));
|
|
32
|
-
const
|
|
33
|
-
const Content_1 = require("../models/
|
|
34
|
-
const ContentKind_1 = require("../models/
|
|
35
|
-
const Device_1 = require("../models/
|
|
36
|
-
const Manifest_1 = require("../models/
|
|
37
|
-
const
|
|
38
|
-
|
|
42
|
+
const models_1 = require("../models");
|
|
43
|
+
const Content_1 = require("../models/Content");
|
|
44
|
+
const ContentKind_1 = require("../models/ContentKind");
|
|
45
|
+
const Device_1 = require("../models/Device");
|
|
46
|
+
const Manifest_1 = require("../models/Manifest");
|
|
47
|
+
const User_1 = require("../models/User");
|
|
48
|
+
// Register the ShareDB types
|
|
39
49
|
const Json1 = __importStar(require("./PermissiveJson1"));
|
|
40
50
|
const RichText = require('@shaxpir/rich-text');
|
|
41
51
|
const UnicodeText = require('ot-text-unicode');
|
|
@@ -331,16 +341,13 @@ class ShareSync {
|
|
|
331
341
|
return new Manifest_1.Manifest(doc, shouldAcquire, shareSync);
|
|
332
342
|
}
|
|
333
343
|
else if (kind === ContentKind_1.ContentKind.USER) {
|
|
334
|
-
return new User_1.
|
|
344
|
+
return new User_1.User(doc, shouldAcquire, shareSync);
|
|
335
345
|
}
|
|
336
346
|
else if (kind === ContentKind_1.ContentKind.DEVICE) {
|
|
337
347
|
return new Device_1.Device(doc, shouldAcquire, shareSync);
|
|
338
348
|
}
|
|
339
|
-
else if (kind === ContentKind_1.ContentKind.BILLING) {
|
|
340
|
-
return new Billing_1.Billing(doc, shouldAcquire, shareSync);
|
|
341
|
-
}
|
|
342
349
|
else if (kind === ContentKind_1.ContentKind.PROFILE) {
|
|
343
|
-
return new
|
|
350
|
+
return new models_1.Profile(doc, shouldAcquire, shareSync);
|
|
344
351
|
}
|
|
345
352
|
throw new Error(`can't wrap content ${kind}/${doc.id}`);
|
|
346
353
|
}
|
package/dist/repo/index.d.ts
CHANGED
package/dist/repo/index.js
CHANGED
|
@@ -18,3 +18,4 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
18
18
|
__exportStar(require("./ConnectionListener"), exports);
|
|
19
19
|
__exportStar(require("./PermissiveJson1"), exports);
|
|
20
20
|
__exportStar(require("./ShareSync"), exports);
|
|
21
|
+
__exportStar(require("./TextEditOps"), exports);
|
package/dist/util/index.d.ts
CHANGED
package/dist/util/index.js
CHANGED
|
@@ -15,11 +15,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
16
16
|
};
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
__exportStar(require("./Base62"), exports);
|
|
19
|
-
__exportStar(require("./CachingHasher"), exports);
|
|
20
|
-
__exportStar(require("./Dispatch"), exports);
|
|
21
18
|
__exportStar(require("./Encryption"), exports);
|
|
22
19
|
__exportStar(require("./Logging"), exports);
|
|
23
|
-
__exportStar(require("./NumberFormat"), exports);
|
|
24
|
-
__exportStar(require("./Struct"), exports);
|
|
25
|
-
__exportStar(require("./Tuples"), exports);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Struct } from
|
|
2
|
-
import { BatchOperation, JsonPath, JsonPathSelect } from "../markup/Operation";
|
|
1
|
+
import { JsonPath, Struct } from '@shaxpir/shaxpir-common';
|
|
3
2
|
import { Content } from "./Content";
|
|
3
|
+
import { BatchOperation, JsonPathSelect } from './Operation';
|
|
4
4
|
|
|
5
5
|
export class ArrayView<T> {
|
|
6
6
|
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Struct } from "@shaxpir/shaxpir-common";
|
|
2
|
+
import { ReviewResult } from "./Review";
|
|
3
|
+
|
|
4
|
+
export interface BayesianScore {
|
|
5
|
+
alpha:number;
|
|
6
|
+
beta:number;
|
|
7
|
+
theta:number;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export class BayesianScoreModel {
|
|
11
|
+
public static apply(
|
|
12
|
+
prevScore:BayesianScore,
|
|
13
|
+
result:ReviewResult,
|
|
14
|
+
weight:number
|
|
15
|
+
):BayesianScore {
|
|
16
|
+
if (isNaN(weight) || !isFinite(weight) || weight < 0 || weight > 1) {
|
|
17
|
+
throw new Error(`illegal weight value: ${weight}`);
|
|
18
|
+
}
|
|
19
|
+
const nextScore = Struct.clone(prevScore) as BayesianScore;
|
|
20
|
+
if (result == 'EASY') {
|
|
21
|
+
nextScore.alpha += (weight * 1.0);
|
|
22
|
+
} else if (result == 'GOOD') {
|
|
23
|
+
nextScore.alpha += (weight * 0.7);
|
|
24
|
+
} else if (result == 'HARD') {
|
|
25
|
+
nextScore.beta += (weight * 0.3);
|
|
26
|
+
} else if (result == 'FAIL') {
|
|
27
|
+
nextScore.beta += (weight * 1.0);
|
|
28
|
+
}
|
|
29
|
+
nextScore.theta = nextScore.alpha / (nextScore.alpha + nextScore.beta);
|
|
30
|
+
return nextScore;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Tuples } from "@shaxpir/shaxpir-common";
|
|
2
2
|
import * as Changesets from 'json-diff-ts';
|
|
3
3
|
import { Operation } from "json-diff-ts";
|
|
4
|
-
import {
|
|
5
|
-
import { Model } from "../content/Model";
|
|
4
|
+
import { Model } from "./Model";
|
|
6
5
|
|
|
7
6
|
export interface ChangeItem {
|
|
8
7
|
type:Operation;
|
|
@@ -15,7 +14,7 @@ export interface ModelChange {
|
|
|
15
14
|
local:boolean;
|
|
16
15
|
model:Model;
|
|
17
16
|
items:ChangeItem[];
|
|
18
|
-
op:
|
|
17
|
+
op:any[];
|
|
19
18
|
}
|
|
20
19
|
|
|
21
20
|
export class Changes {
|