@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
|
@@ -4,15 +4,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.Metric = exports.MetricName = void 0;
|
|
7
|
+
const shaxpir_common_1 = require("@shaxpir/shaxpir-common");
|
|
7
8
|
const dayjs_1 = __importDefault(require("dayjs"));
|
|
8
9
|
const utc_1 = __importDefault(require("dayjs/plugin/utc"));
|
|
9
|
-
|
|
10
|
-
const ShareSync_1 = require("../../repo/ShareSync");
|
|
11
|
-
const CachingHasher_1 = require("../../util/CachingHasher");
|
|
12
|
-
const Operation_1 = require("../markup/Operation");
|
|
10
|
+
const repo_1 = require("../repo");
|
|
13
11
|
const Content_1 = require("./Content");
|
|
14
12
|
const ContentKind_1 = require("./ContentKind");
|
|
15
|
-
const
|
|
13
|
+
const Operation_1 = require("./Operation");
|
|
14
|
+
dayjs_1.default.extend(utc_1.default);
|
|
16
15
|
var MetricName;
|
|
17
16
|
(function (MetricName) {
|
|
18
17
|
MetricName["WORD_COUNT"] = "word_count";
|
|
@@ -20,7 +19,7 @@ var MetricName;
|
|
|
20
19
|
})(MetricName || (exports.MetricName = MetricName = {}));
|
|
21
20
|
class Metric extends Content_1.Content {
|
|
22
21
|
static makeMetricId(userId, metricName) {
|
|
23
|
-
return
|
|
22
|
+
return shaxpir_common_1.CachingHasher.makeMd5Base62Hash(userId + "-metric-" + metricName);
|
|
24
23
|
}
|
|
25
24
|
static create(userId, metricName, entries) {
|
|
26
25
|
const metricId = Metric.makeMetricId(userId, metricName);
|
|
@@ -29,18 +28,17 @@ class Metric extends Content_1.Content {
|
|
|
29
28
|
let maxDate = null;
|
|
30
29
|
for (let d of Object.keys(entries)) {
|
|
31
30
|
const date = d;
|
|
32
|
-
if (minDate === null ||
|
|
31
|
+
if (minDate === null || shaxpir_common_1.Time.compareDate(date, minDate) < 0) {
|
|
33
32
|
minDate = date;
|
|
34
33
|
}
|
|
35
|
-
if (maxDate === null ||
|
|
34
|
+
if (maxDate === null || shaxpir_common_1.Time.compareDate(date, maxDate) > 0) {
|
|
36
35
|
maxDate = date;
|
|
37
36
|
}
|
|
38
37
|
}
|
|
39
|
-
const now =
|
|
40
|
-
return
|
|
38
|
+
const now = shaxpir_common_1.MultiClock.now();
|
|
39
|
+
return repo_1.ShareSyncFactory.get().createContent({
|
|
41
40
|
meta: {
|
|
42
41
|
ref: metricId,
|
|
43
|
-
is_head: true,
|
|
44
42
|
kind: ContentKind_1.ContentKind.METRIC,
|
|
45
43
|
id: metricId,
|
|
46
44
|
owner: userId,
|
|
@@ -76,8 +74,8 @@ class Metric extends Content_1.Content {
|
|
|
76
74
|
}
|
|
77
75
|
get length() {
|
|
78
76
|
this.checkDisposed("Metric.length");
|
|
79
|
-
const minMoment = dayjs_1.default.utc(this.minDate,
|
|
80
|
-
const maxMoment = dayjs_1.default.utc(this.maxDate,
|
|
77
|
+
const minMoment = dayjs_1.default.utc(this.minDate, shaxpir_common_1.Time.DATE_FORMAT);
|
|
78
|
+
const maxMoment = dayjs_1.default.utc(this.maxDate, shaxpir_common_1.Time.DATE_FORMAT);
|
|
81
79
|
return Math.abs(maxMoment.diff(minMoment, "days")) + 1;
|
|
82
80
|
}
|
|
83
81
|
get(index) {
|
|
@@ -89,8 +87,8 @@ class Metric extends Content_1.Content {
|
|
|
89
87
|
};
|
|
90
88
|
}
|
|
91
89
|
else {
|
|
92
|
-
const minMoment = dayjs_1.default.utc(this.minDate,
|
|
93
|
-
const offsetDate = minMoment.add(index, 'days').format(
|
|
90
|
+
const minMoment = dayjs_1.default.utc(this.minDate, shaxpir_common_1.Time.DATE_FORMAT);
|
|
91
|
+
const offsetDate = minMoment.add(index, 'days').format(shaxpir_common_1.Time.DATE_FORMAT);
|
|
94
92
|
return {
|
|
95
93
|
date: offsetDate,
|
|
96
94
|
amount: this.forDate(offsetDate)
|
|
@@ -100,7 +98,7 @@ class Metric extends Content_1.Content {
|
|
|
100
98
|
sumBetween(minDate, maxDate) {
|
|
101
99
|
this.checkDisposed("Metric.sumBetween");
|
|
102
100
|
let sum = 0;
|
|
103
|
-
const dates =
|
|
101
|
+
const dates = shaxpir_common_1.Time.datesBetween(minDate, maxDate);
|
|
104
102
|
for (let i = 0, len = dates.length; i < len; i++) {
|
|
105
103
|
const date = dates[i];
|
|
106
104
|
sum += this.forDate(date);
|
|
@@ -132,10 +130,10 @@ class Metric extends Content_1.Content {
|
|
|
132
130
|
const prevMaxDate = this.payload.max_date;
|
|
133
131
|
const batch = new Operation_1.BatchOperation(this);
|
|
134
132
|
batch.setPathValue(['payload', 'entries', date], amount);
|
|
135
|
-
if (prevMinDate === null ||
|
|
133
|
+
if (prevMinDate === null || shaxpir_common_1.Time.compareDate(date, prevMinDate) < 0) {
|
|
136
134
|
batch.setPathValue(['payload', 'min_date'], date);
|
|
137
135
|
}
|
|
138
|
-
if (prevMaxDate === null ||
|
|
136
|
+
if (prevMaxDate === null || shaxpir_common_1.Time.compareDate(date, prevMaxDate) > 0) {
|
|
139
137
|
batch.setPathValue(['payload', 'max_date'], date);
|
|
140
138
|
}
|
|
141
139
|
batch.commit();
|
|
@@ -153,10 +151,10 @@ class Metric extends Content_1.Content {
|
|
|
153
151
|
const prevAmount = this.forDate(date);
|
|
154
152
|
const newAmount = dateAmounts[date];
|
|
155
153
|
batch.setPathValue(['payload', 'entries', date], prevAmount + newAmount);
|
|
156
|
-
if (minDate === null ||
|
|
154
|
+
if (minDate === null || shaxpir_common_1.Time.compareDate(date, minDate) < 0) {
|
|
157
155
|
minDate = date;
|
|
158
156
|
}
|
|
159
|
-
if (maxDate === null ||
|
|
157
|
+
if (maxDate === null || shaxpir_common_1.Time.compareDate(date, maxDate) > 0) {
|
|
160
158
|
maxDate = date;
|
|
161
159
|
}
|
|
162
160
|
}
|
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
/// <reference path="../../../decs.d.ts" />
|
|
2
1
|
import { Doc } from '@shaxpir/sharedb/lib/client';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { ContentId, ContentMeta, ContentRef } from
|
|
2
|
+
import { CompactDateTime, DispatchTopic } from '@shaxpir/shaxpir-common';
|
|
3
|
+
import { ShareSync } from '../repo';
|
|
4
|
+
import { ContentId, ContentMeta, ContentRef } from "./Content";
|
|
6
5
|
import { ContentKind } from './ContentKind';
|
|
7
6
|
import { ManifestBody } from './Manifest';
|
|
8
7
|
import { PermissionType } from './Permissions';
|
|
9
|
-
import { CompactDateTime } from './Time';
|
|
10
8
|
export declare abstract class Model {
|
|
11
9
|
static CHANGED: DispatchTopic;
|
|
12
10
|
doc: Doc;
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Model = void 0;
|
|
4
|
-
const
|
|
5
|
-
const Dispatch_1 = require("../../util/Dispatch");
|
|
6
|
-
const ChangeModel_1 = require("../markup/ChangeModel");
|
|
4
|
+
const shaxpir_common_1 = require("@shaxpir/shaxpir-common");
|
|
7
5
|
const ContentKind_1 = require("./ContentKind");
|
|
8
6
|
const Permissions_1 = require("./Permissions");
|
|
7
|
+
const ChangeModel_1 = require("./ChangeModel");
|
|
9
8
|
class Model {
|
|
10
9
|
constructor(doc, shouldAcquire, shareSync) {
|
|
11
10
|
this._dataBeforeOpBatch = null;
|
|
@@ -24,13 +23,13 @@ class Model {
|
|
|
24
23
|
}
|
|
25
24
|
const onBeforeOpBatch = function (op, source) {
|
|
26
25
|
if (model._shouldPerformModelChangeAnalysis) {
|
|
27
|
-
model._dataBeforeOpBatch =
|
|
26
|
+
model._dataBeforeOpBatch = shaxpir_common_1.Struct.clone(model.doc.data);
|
|
28
27
|
}
|
|
29
28
|
};
|
|
30
29
|
const onOpBatch = function (op, source) {
|
|
31
30
|
if (model._shouldPerformModelChangeAnalysis) {
|
|
32
31
|
// Use tuple-arrays to perform a diff...
|
|
33
|
-
const dataAfterOpBatch =
|
|
32
|
+
const dataAfterOpBatch = shaxpir_common_1.Struct.clone(model.doc.data);
|
|
34
33
|
let changeItems = ChangeModel_1.ChangeModel.between(model._dataBeforeOpBatch, dataAfterOpBatch);
|
|
35
34
|
model._dataBeforeOpBatch = null;
|
|
36
35
|
// FROM https://share.github.io/sharedb/api/doc ...
|
|
@@ -44,7 +43,7 @@ class Model {
|
|
|
44
43
|
items: changeItems,
|
|
45
44
|
op: op
|
|
46
45
|
};
|
|
47
|
-
|
|
46
|
+
shaxpir_common_1.Dispatch.publish(Model.CHANGED, change);
|
|
48
47
|
}
|
|
49
48
|
};
|
|
50
49
|
model.doc.on('before op batch', onBeforeOpBatch);
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
/// <reference path="../../../decs.d.ts" />
|
|
2
|
-
import { Op as DeltaOp } from "@shaxpir/quill-delta";
|
|
3
1
|
import { Doc } from '@shaxpir/sharedb/lib/client';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
2
|
+
import { MultiTime } from '@shaxpir/shaxpir-common';
|
|
3
|
+
import { Model } from './Model';
|
|
6
4
|
export type JsonPathElement = string | number;
|
|
7
5
|
export type JsonPath = JsonPathElement[];
|
|
8
6
|
export interface PathVal {
|
|
@@ -27,6 +25,5 @@ export declare class BatchOperation {
|
|
|
27
25
|
pushIntoArray(path: JsonPath, value: any): void;
|
|
28
26
|
removeValueAtPath(path: JsonPath): void;
|
|
29
27
|
replaceValueAtPath(path: JsonPath, value: any): void;
|
|
30
|
-
applyRichText(path: JsonPath, deltaOps: DeltaOp[]): void;
|
|
31
28
|
commit(): void;
|
|
32
29
|
}
|
|
@@ -15,22 +15,30 @@ 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
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
36
|
exports.BatchOperation = exports.JsonPathSelect = void 0;
|
|
27
|
-
const
|
|
28
|
-
const
|
|
29
|
-
const
|
|
30
|
-
const
|
|
31
|
-
const
|
|
32
|
-
const Json1 = __importStar(require("../../repo/PermissiveJson1"));
|
|
33
|
-
const RichText = require('@shaxpir/rich-text');
|
|
37
|
+
const shaxpir_common_1 = require("@shaxpir/shaxpir-common");
|
|
38
|
+
const TextEditOps_1 = require("../repo/TextEditOps");
|
|
39
|
+
const Json1 = __importStar(require("../repo/PermissiveJson1"));
|
|
40
|
+
const repo_1 = require("../repo");
|
|
41
|
+
const Content_1 = require("./Content");
|
|
34
42
|
const UnicodeText = require('ot-text-unicode');
|
|
35
43
|
;
|
|
36
44
|
class JsonPathSelect {
|
|
@@ -69,12 +77,12 @@ class BatchOperation {
|
|
|
69
77
|
this.time = time;
|
|
70
78
|
}
|
|
71
79
|
else {
|
|
72
|
-
this.time =
|
|
80
|
+
this.time = shaxpir_common_1.MultiClock.now();
|
|
73
81
|
}
|
|
74
82
|
this.ops = [];
|
|
75
83
|
}
|
|
76
84
|
get at() {
|
|
77
|
-
return
|
|
85
|
+
return shaxpir_common_1.Struct.clone(this.time);
|
|
78
86
|
}
|
|
79
87
|
hasOps() {
|
|
80
88
|
return this.ops.length > 0;
|
|
@@ -87,7 +95,7 @@ class BatchOperation {
|
|
|
87
95
|
if (prevValue === null) {
|
|
88
96
|
this.ops.push(Json1.replaceOp(path, prevValue, value));
|
|
89
97
|
}
|
|
90
|
-
else if (!
|
|
98
|
+
else if (!shaxpir_common_1.Struct.equals(prevValue, value)) {
|
|
91
99
|
const textEditOps = TextEditOps_1.TextEditOps.between(prevValue, value);
|
|
92
100
|
this.ops.push(Json1.editOp(path, UnicodeText.type, textEditOps));
|
|
93
101
|
}
|
|
@@ -99,7 +107,7 @@ class BatchOperation {
|
|
|
99
107
|
setPathValue(path, value) {
|
|
100
108
|
const prevValue = JsonPathSelect.getValueAtPath(this.model.doc, path);
|
|
101
109
|
if (prevValue !== undefined) {
|
|
102
|
-
if (!
|
|
110
|
+
if (!shaxpir_common_1.Struct.equals(prevValue, value)) {
|
|
103
111
|
this.ops.push(Json1.replaceOp(path, prevValue, value));
|
|
104
112
|
}
|
|
105
113
|
}
|
|
@@ -119,13 +127,13 @@ class BatchOperation {
|
|
|
119
127
|
if (!Array.isArray(array)) {
|
|
120
128
|
throw new Error(`path '${JSON.stringify(arrayPath)}' does not refer to an array: ${JSON.stringify(this.model.doc.data)}`);
|
|
121
129
|
}
|
|
122
|
-
const path =
|
|
130
|
+
const path = shaxpir_common_1.Struct.clone(arrayPath);
|
|
123
131
|
path.push(index);
|
|
124
132
|
this.ops.push(Json1.insertOp(path, value));
|
|
125
133
|
}
|
|
126
134
|
}
|
|
127
135
|
unshiftIntoArray(path, value) {
|
|
128
|
-
path =
|
|
136
|
+
path = shaxpir_common_1.Struct.clone(path);
|
|
129
137
|
let array = JsonPathSelect.getValueAtPath(this.model.doc, path);
|
|
130
138
|
if (array === undefined) {
|
|
131
139
|
this.ops.push(Json1.insertOp(path, [value]));
|
|
@@ -139,7 +147,7 @@ class BatchOperation {
|
|
|
139
147
|
}
|
|
140
148
|
}
|
|
141
149
|
pushIntoArray(path, value) {
|
|
142
|
-
path =
|
|
150
|
+
path = shaxpir_common_1.Struct.clone(path);
|
|
143
151
|
let array = JsonPathSelect.getValueAtPath(this.model.doc, path);
|
|
144
152
|
if (array === undefined) {
|
|
145
153
|
this.ops.push(Json1.insertOp(path, [value]));
|
|
@@ -167,9 +175,6 @@ class BatchOperation {
|
|
|
167
175
|
this.ops.push(Json1.insertOp(path, value));
|
|
168
176
|
}
|
|
169
177
|
}
|
|
170
|
-
applyRichText(path, deltaOps) {
|
|
171
|
-
this.ops.push(Json1.editOp(path, RichText.type, deltaOps));
|
|
172
|
-
}
|
|
173
178
|
commit() {
|
|
174
179
|
const batch = this;
|
|
175
180
|
if (batch.ops.length > 0) {
|
|
@@ -179,7 +184,7 @@ class BatchOperation {
|
|
|
179
184
|
this.setPathValue(['meta', 'updated_at', 'local_time'], batch.time.local_time);
|
|
180
185
|
}
|
|
181
186
|
const reduced = batch.ops.reduce(Json1.type.compose, null);
|
|
182
|
-
const shareSync =
|
|
187
|
+
const shareSync = repo_1.ShareSyncFactory.get();
|
|
183
188
|
batch.model.doc.submitOp(reduced, (error) => {
|
|
184
189
|
if (error) {
|
|
185
190
|
shareSync.onOperationError(error);
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { CompactDateTime } from "@shaxpir/shaxpir-common";
|
|
2
|
+
import { ContentId } from "./Content";
|
|
3
|
+
import { ReviewLike } from "./Review";
|
|
4
|
+
export interface PhraseExample {
|
|
5
|
+
id: number;
|
|
6
|
+
text: string;
|
|
7
|
+
pinyin: string;
|
|
8
|
+
translation: string;
|
|
9
|
+
learn_rank: number;
|
|
10
|
+
sense_rank: number;
|
|
11
|
+
}
|
|
12
|
+
export interface Phrase {
|
|
13
|
+
text: string;
|
|
14
|
+
hanzi_count: number;
|
|
15
|
+
sense_rank: number;
|
|
16
|
+
learn_rank: number;
|
|
17
|
+
pinyin: string;
|
|
18
|
+
pinyin_tokenized: string;
|
|
19
|
+
transliteration: string;
|
|
20
|
+
translation: string;
|
|
21
|
+
notes: string;
|
|
22
|
+
examples?: PhraseExample[];
|
|
23
|
+
components?: PhraseExample[];
|
|
24
|
+
keywords?: string[];
|
|
25
|
+
tags?: string[];
|
|
26
|
+
}
|
|
27
|
+
export interface BuiltInPhrase extends Phrase {
|
|
28
|
+
id: number;
|
|
29
|
+
}
|
|
30
|
+
export interface AnnotatedPhrase extends Phrase {
|
|
31
|
+
id: string;
|
|
32
|
+
phrase_id?: number;
|
|
33
|
+
content_id?: ContentId;
|
|
34
|
+
starred_at: CompactDateTime | null;
|
|
35
|
+
alpha: number;
|
|
36
|
+
beta: number;
|
|
37
|
+
proficiency: number;
|
|
38
|
+
reviews: ReviewLike[];
|
|
39
|
+
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
/// <reference path="../../../decs.d.ts" />
|
|
2
1
|
import { Doc } from '@shaxpir/sharedb/lib/client';
|
|
3
|
-
import { ShareSync } from '
|
|
2
|
+
import { ShareSync } from '../repo';
|
|
4
3
|
import { Content, ContentBody, ContentId, ContentMeta } from "./Content";
|
|
5
4
|
import { MediaCropping } from './Media';
|
|
6
5
|
export interface ProfilePayload {
|
|
@@ -1,23 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Profile = void 0;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const Operation_1 = require("../markup/Operation");
|
|
4
|
+
const shaxpir_common_1 = require("@shaxpir/shaxpir-common");
|
|
5
|
+
const repo_1 = require("../repo");
|
|
7
6
|
const Content_1 = require("./Content");
|
|
8
7
|
const ContentKind_1 = require("./ContentKind");
|
|
9
|
-
const
|
|
8
|
+
const Operation_1 = require("./Operation");
|
|
10
9
|
class Profile extends Content_1.Content {
|
|
11
10
|
static makeProfileId(userId) {
|
|
12
|
-
return
|
|
11
|
+
return shaxpir_common_1.CachingHasher.makeMd5Base62Hash(userId + "-" + ContentKind_1.ContentKind.PROFILE);
|
|
13
12
|
}
|
|
14
13
|
static create(userId) {
|
|
15
|
-
const now =
|
|
14
|
+
const now = shaxpir_common_1.MultiClock.now();
|
|
16
15
|
const profileId = Profile.makeProfileId(userId);
|
|
17
|
-
return
|
|
16
|
+
return repo_1.ShareSyncFactory.get().createContent({
|
|
18
17
|
meta: {
|
|
19
18
|
ref: profileId,
|
|
20
|
-
is_head: true,
|
|
21
19
|
kind: ContentKind_1.ContentKind.PROFILE,
|
|
22
20
|
id: profileId,
|
|
23
21
|
owner: userId,
|
|
@@ -88,7 +86,7 @@ class Profile extends Content_1.Content {
|
|
|
88
86
|
}
|
|
89
87
|
}
|
|
90
88
|
static async findByUsername(username) {
|
|
91
|
-
const shareSync =
|
|
89
|
+
const shareSync = repo_1.ShareSyncFactory.get();
|
|
92
90
|
return shareSync.findAndAcquire(ContentKind_1.ContentKind.PROFILE, { "payload.username": username });
|
|
93
91
|
}
|
|
94
92
|
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Doc } from '@shaxpir/sharedb/lib/client';
|
|
2
|
+
import { CompactDateTime } from "@shaxpir/shaxpir-common";
|
|
3
|
+
import { ShareSync } from '../repo';
|
|
4
|
+
import { BayesianScore } from './BayesianScore';
|
|
5
|
+
import { Content, ContentBody, ContentId, ContentMeta } from "./Content";
|
|
6
|
+
export interface PhraseProgress extends BayesianScore {
|
|
7
|
+
text: string;
|
|
8
|
+
sense_rank: number;
|
|
9
|
+
learn_rank: number;
|
|
10
|
+
last_review_utc?: CompactDateTime;
|
|
11
|
+
}
|
|
12
|
+
export interface ProgressPayload {
|
|
13
|
+
user_rank: number;
|
|
14
|
+
phrases: Record<string, PhraseProgress>;
|
|
15
|
+
cognitive_load: number;
|
|
16
|
+
}
|
|
17
|
+
export interface ProgressBody extends ContentBody {
|
|
18
|
+
meta: ContentMeta;
|
|
19
|
+
payload: ProgressPayload;
|
|
20
|
+
}
|
|
21
|
+
export declare class Progress extends Content {
|
|
22
|
+
static makeProgressId(userId: ContentId): ContentId;
|
|
23
|
+
static create(userId: ContentId): Progress;
|
|
24
|
+
constructor(doc: Doc, shouldAcquire: boolean, shareSync: ShareSync);
|
|
25
|
+
get payload(): ProgressPayload;
|
|
26
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Progress = void 0;
|
|
4
|
+
const shaxpir_common_1 = require("@shaxpir/shaxpir-common");
|
|
5
|
+
const repo_1 = require("../repo");
|
|
6
|
+
const Content_1 = require("./Content");
|
|
7
|
+
const ContentKind_1 = require("./ContentKind");
|
|
8
|
+
class Progress extends Content_1.Content {
|
|
9
|
+
static makeProgressId(userId) {
|
|
10
|
+
return shaxpir_common_1.CachingHasher.makeMd5Base62Hash(userId + "-" + ContentKind_1.ContentKind.PROGRESS);
|
|
11
|
+
}
|
|
12
|
+
static create(userId) {
|
|
13
|
+
const now = shaxpir_common_1.MultiClock.now();
|
|
14
|
+
const progressId = Progress.makeProgressId(userId);
|
|
15
|
+
return repo_1.ShareSyncFactory.get().createContent({
|
|
16
|
+
meta: {
|
|
17
|
+
ref: progressId,
|
|
18
|
+
kind: ContentKind_1.ContentKind.PROGRESS,
|
|
19
|
+
id: progressId,
|
|
20
|
+
owner: userId,
|
|
21
|
+
created_at: now,
|
|
22
|
+
updated_at: now
|
|
23
|
+
},
|
|
24
|
+
payload: {
|
|
25
|
+
user_rank: 0,
|
|
26
|
+
phrases: {},
|
|
27
|
+
cognitive_load: 0
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
constructor(doc, shouldAcquire, shareSync) {
|
|
32
|
+
super(doc, shouldAcquire, shareSync);
|
|
33
|
+
}
|
|
34
|
+
get payload() {
|
|
35
|
+
this.checkDisposed("Progress.payload");
|
|
36
|
+
return this.doc.data.payload;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
exports.Progress = Progress;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { MultiTime } from "@shaxpir/shaxpir-common";
|
|
2
|
+
export type ReviewResult = 'FAIL' | 'HARD' | 'GOOD' | 'EASY';
|
|
3
|
+
export interface ReviewLike {
|
|
4
|
+
result: ReviewResult;
|
|
5
|
+
at: MultiTime;
|
|
6
|
+
}
|
|
7
|
+
export interface Review extends ReviewLike {
|
|
8
|
+
text: string;
|
|
9
|
+
sense_rank: number;
|
|
10
|
+
}
|
|
11
|
+
export interface ImpliedReview extends ReviewLike {
|
|
12
|
+
context: string;
|
|
13
|
+
weight: number;
|
|
14
|
+
}
|
|
@@ -1,19 +1,15 @@
|
|
|
1
|
-
/// <reference path="../../../decs.d.ts" />
|
|
2
1
|
import { Doc } from '@shaxpir/sharedb/lib/client';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { Content, ContentBody, ContentId, ContentMeta } from "./Content";
|
|
6
|
-
import {
|
|
7
|
-
import { MultiTime } from "./Time";
|
|
2
|
+
import { MultiTime } from "@shaxpir/shaxpir-common";
|
|
3
|
+
import { ShareSync } from '../repo';
|
|
4
|
+
import { Content, ContentBody, ContentId, ContentMeta, ContentRef } from "./Content";
|
|
5
|
+
import { Review } from './Review';
|
|
8
6
|
export interface SessionPayload {
|
|
9
7
|
start: MultiTime;
|
|
10
8
|
end: MultiTime;
|
|
11
9
|
tz_offset: number;
|
|
12
10
|
device_id: ContentId;
|
|
13
11
|
duration_minutes: number;
|
|
14
|
-
|
|
15
|
-
word_count: number;
|
|
16
|
-
activity: Activity[];
|
|
12
|
+
reviews: Review[];
|
|
17
13
|
}
|
|
18
14
|
export interface SessionBody extends ContentBody {
|
|
19
15
|
meta: ContentMeta;
|
|
@@ -21,7 +17,8 @@ export interface SessionBody extends ContentBody {
|
|
|
21
17
|
}
|
|
22
18
|
export declare class Session extends Content {
|
|
23
19
|
static makeSessionId(userId: ContentId): ContentId;
|
|
24
|
-
static
|
|
20
|
+
static makeSessionRef(userId: ContentId, at: MultiTime): ContentRef;
|
|
21
|
+
static create(userId: ContentId, deviceId: ContentId): Session;
|
|
25
22
|
constructor(doc: Doc, shouldAcquire: boolean, shareSync: ShareSync);
|
|
26
23
|
get payload(): SessionPayload;
|
|
27
24
|
touch(): void;
|
|
@@ -30,10 +27,5 @@ export declare class Session extends Content {
|
|
|
30
27
|
get tzOffset(): number;
|
|
31
28
|
get durationMinutes(): number;
|
|
32
29
|
get deviceId(): ContentId;
|
|
33
|
-
get environment(): Environment;
|
|
34
|
-
get wordCount(): number;
|
|
35
|
-
setWordCount(value: number): void;
|
|
36
|
-
get activity(): Activity[];
|
|
37
|
-
recordActivity(newActivity: Activity): void;
|
|
38
30
|
modelUpdated(): Promise<void>;
|
|
39
31
|
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Session = void 0;
|
|
4
|
+
const shaxpir_common_1 = require("@shaxpir/shaxpir-common");
|
|
5
|
+
const repo_1 = require("../repo");
|
|
6
|
+
const Content_1 = require("./Content");
|
|
7
|
+
const ContentKind_1 = require("./ContentKind");
|
|
8
|
+
const Metric_1 = require("./Metric");
|
|
9
|
+
const Operation_1 = require("./Operation");
|
|
10
|
+
const Workspace_1 = require("./Workspace");
|
|
11
|
+
class Session extends Content_1.Content {
|
|
12
|
+
static makeSessionId(userId) {
|
|
13
|
+
return shaxpir_common_1.CachingHasher.makeMd5Base62Hash(userId + "-" + ContentKind_1.ContentKind.SESSION);
|
|
14
|
+
}
|
|
15
|
+
static makeSessionRef(userId, at) {
|
|
16
|
+
let sessionId = Session.makeSessionId(userId);
|
|
17
|
+
return `${sessionId}_${at.utc_time}`;
|
|
18
|
+
}
|
|
19
|
+
static create(userId, deviceId) {
|
|
20
|
+
let now = shaxpir_common_1.MultiClock.now();
|
|
21
|
+
let sessionId = Session.makeSessionId(userId);
|
|
22
|
+
let sessionRef = Session.makeSessionRef(userId, now);
|
|
23
|
+
return repo_1.ShareSyncFactory.get().createContent({
|
|
24
|
+
meta: {
|
|
25
|
+
ref: sessionRef,
|
|
26
|
+
kind: ContentKind_1.ContentKind.SESSION,
|
|
27
|
+
id: sessionId,
|
|
28
|
+
owner: userId,
|
|
29
|
+
created_at: now,
|
|
30
|
+
updated_at: now
|
|
31
|
+
},
|
|
32
|
+
payload: {
|
|
33
|
+
start: now,
|
|
34
|
+
end: now,
|
|
35
|
+
tz_offset: (new Date()).getTimezoneOffset(),
|
|
36
|
+
duration_minutes: 0,
|
|
37
|
+
device_id: deviceId,
|
|
38
|
+
reviews: []
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
constructor(doc, shouldAcquire, shareSync) {
|
|
43
|
+
super(doc, shouldAcquire, shareSync);
|
|
44
|
+
}
|
|
45
|
+
get payload() {
|
|
46
|
+
this.checkDisposed("Session.payload");
|
|
47
|
+
return this.doc.data.payload;
|
|
48
|
+
}
|
|
49
|
+
touch() {
|
|
50
|
+
this.checkDisposed("Session.touch");
|
|
51
|
+
const batch = new Operation_1.BatchOperation(this);
|
|
52
|
+
let nowUtc = batch.at.utc_time;
|
|
53
|
+
let nowLocal = batch.at.local_time;
|
|
54
|
+
let minutes = shaxpir_common_1.Time.absDiffMinutes(nowUtc, this.start.utc_time);
|
|
55
|
+
batch.setPathValue(['payload', 'duration_minutes'], minutes);
|
|
56
|
+
batch.setPathValue(['payload', 'end', 'utc_time'], nowUtc);
|
|
57
|
+
batch.setPathValue(['payload', 'end', 'local_time'], nowLocal);
|
|
58
|
+
batch.commit();
|
|
59
|
+
}
|
|
60
|
+
get start() {
|
|
61
|
+
this.checkDisposed("Session.start");
|
|
62
|
+
return this.payload.start;
|
|
63
|
+
}
|
|
64
|
+
get end() {
|
|
65
|
+
this.checkDisposed("Session.end");
|
|
66
|
+
return this.payload.end;
|
|
67
|
+
}
|
|
68
|
+
get tzOffset() {
|
|
69
|
+
this.checkDisposed("Session.tzOffset");
|
|
70
|
+
return this.payload.tz_offset;
|
|
71
|
+
}
|
|
72
|
+
get durationMinutes() {
|
|
73
|
+
this.checkDisposed("Session.durationMinutes");
|
|
74
|
+
return this.payload.duration_minutes;
|
|
75
|
+
}
|
|
76
|
+
get deviceId() {
|
|
77
|
+
this.checkDisposed("Session.deviceId");
|
|
78
|
+
return this.payload.device_id;
|
|
79
|
+
}
|
|
80
|
+
async modelUpdated() {
|
|
81
|
+
this.checkDisposed("Session.modelUpdated");
|
|
82
|
+
await super.modelUpdated();
|
|
83
|
+
const shareSync = this.shareSync;
|
|
84
|
+
const sessionId = this.id;
|
|
85
|
+
const userId = this.owner;
|
|
86
|
+
const date = shaxpir_common_1.Time.dateFrom(this.createdAt.local_time);
|
|
87
|
+
const workspaceId = Workspace_1.Workspace.makeWorkspaceId(userId);
|
|
88
|
+
const workspace = await this.shareSync.acquire(ContentKind_1.ContentKind.WORKSPACE, workspaceId);
|
|
89
|
+
const sessionsOnDate = await workspace.acquireSessionsFromDate(sessionId, date);
|
|
90
|
+
workspace.release();
|
|
91
|
+
let minutesWritingOnDate = 0;
|
|
92
|
+
for (let i = 0, len = sessionsOnDate.length; i < len; i++) {
|
|
93
|
+
const sessionOnDate = sessionsOnDate[i];
|
|
94
|
+
minutesWritingOnDate += sessionOnDate.durationMinutes;
|
|
95
|
+
sessionOnDate.release();
|
|
96
|
+
}
|
|
97
|
+
const minutesWritingMetricId = Metric_1.Metric.makeMetricId(userId, Metric_1.MetricName.MINUTES_WRITING);
|
|
98
|
+
const minutesWritingMetric = await shareSync.acquire(ContentKind_1.ContentKind.METRIC, minutesWritingMetricId);
|
|
99
|
+
minutesWritingMetric.setDateAmount(date, minutesWritingOnDate);
|
|
100
|
+
minutesWritingMetric.release();
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
exports.Session = Session;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Doc } from '@shaxpir/sharedb/lib/client';
|
|
2
|
+
import { CompactDateTime } from "@shaxpir/shaxpir-common";
|
|
3
|
+
import { BayesianScore } from './BayesianScore';
|
|
4
|
+
import { Content, ContentBody, ContentId, ContentMeta } from "./Content";
|
|
5
|
+
import { BuiltInPhrase, Phrase, PhraseExample } from './Phrase';
|
|
6
|
+
import { ReviewLike } from "./Review";
|
|
7
|
+
import { ShareSync } from '../repo';
|
|
8
|
+
export interface TermPayload extends BayesianScore {
|
|
9
|
+
text: string;
|
|
10
|
+
sense_rank: number;
|
|
11
|
+
learn_rank: number;
|
|
12
|
+
phrase_id: number | null;
|
|
13
|
+
starred_at: CompactDateTime | null;
|
|
14
|
+
hanzi_count?: number;
|
|
15
|
+
pinyin?: string;
|
|
16
|
+
pinyin_tokenized?: string;
|
|
17
|
+
transliteration?: string;
|
|
18
|
+
translation?: string;
|
|
19
|
+
notes?: string;
|
|
20
|
+
components?: PhraseExample[];
|
|
21
|
+
examples?: PhraseExample[];
|
|
22
|
+
keywords?: string[];
|
|
23
|
+
tags: string[];
|
|
24
|
+
reviews: ReviewLike[];
|
|
25
|
+
}
|
|
26
|
+
export interface TermBody extends ContentBody {
|
|
27
|
+
meta: ContentMeta;
|
|
28
|
+
payload: TermPayload;
|
|
29
|
+
}
|
|
30
|
+
export declare class Term extends Content {
|
|
31
|
+
static makeTermId(userId: ContentId, text: string, senseRank: number): ContentId;
|
|
32
|
+
static forUserPhrase(userId: ContentId, phrase: Phrase): Term;
|
|
33
|
+
static forBuiltinPhrase(userId: ContentId, phrase: BuiltInPhrase): Term;
|
|
34
|
+
constructor(doc: Doc, shouldAcquire: boolean, shareSync: ShareSync);
|
|
35
|
+
get payload(): TermPayload;
|
|
36
|
+
}
|