@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.
Files changed (224) hide show
  1. package/dist/models/{content/ArrayView.d.ts → ArrayView.d.ts} +1 -1
  2. package/dist/models/{content/ArrayView.js → ArrayView.js} +14 -14
  3. package/dist/models/BayesianScore.d.ts +9 -0
  4. package/dist/models/BayesianScore.js +27 -0
  5. package/dist/models/{markup/ChangeModel.d.ts → ChangeModel.d.ts} +2 -3
  6. package/dist/models/{markup/ChangeModel.js → ChangeModel.js} +20 -10
  7. package/dist/models/{content/Content.d.ts → Content.d.ts} +9 -10
  8. package/dist/models/{content/Content.js → Content.js} +2 -6
  9. package/dist/models/{content/ContentKind.d.ts → ContentKind.d.ts} +3 -0
  10. package/dist/models/{content/ContentKind.js → ContentKind.js} +5 -1
  11. package/dist/models/{content/Device.d.ts → Device.d.ts} +15 -7
  12. package/dist/models/{content/Device.js → Device.js} +14 -18
  13. package/dist/models/Hanzi.d.ts +15 -0
  14. package/dist/models/{content/Manifest.d.ts → Manifest.d.ts} +7 -3
  15. package/dist/models/{content/Manifest.js → Manifest.js} +12 -8
  16. package/dist/models/{content/Media.d.ts → Media.d.ts} +2 -3
  17. package/dist/models/{content/Media.js → Media.js} +4 -5
  18. package/dist/models/{content/Metric.d.ts → Metric.d.ts} +2 -3
  19. package/dist/models/{content/Metric.js → Metric.js} +18 -20
  20. package/dist/models/{content/Model.d.ts → Model.d.ts} +3 -5
  21. package/dist/models/{content/Model.js → Model.js} +5 -6
  22. package/dist/models/{markup/Operation.d.ts → Operation.d.ts} +2 -5
  23. package/dist/models/{markup/Operation.js → Operation.js} +30 -25
  24. package/dist/models/Phrase.d.ts +39 -0
  25. package/dist/models/{content/Profile.d.ts → Profile.d.ts} +1 -2
  26. package/dist/models/{content/Profile.js → Profile.js} +7 -9
  27. package/dist/models/Progress.d.ts +26 -0
  28. package/dist/models/Progress.js +39 -0
  29. package/dist/models/Review.d.ts +14 -0
  30. package/dist/models/{content/Session.d.ts → Session.d.ts} +7 -15
  31. package/dist/models/Session.js +103 -0
  32. package/dist/models/Term.d.ts +36 -0
  33. package/dist/models/Term.js +82 -0
  34. package/dist/models/User.d.ts +32 -0
  35. package/dist/models/User.js +65 -0
  36. package/dist/models/Workspace.d.ts +37 -0
  37. package/dist/models/Workspace.js +94 -0
  38. package/dist/models/index.d.ts +22 -2
  39. package/dist/models/index.js +22 -2
  40. package/dist/repo/PermissiveJson1.d.ts +16 -16
  41. package/dist/repo/PermissiveJson1.js +17 -7
  42. package/dist/repo/ShareSync.d.ts +6 -6
  43. package/dist/repo/ShareSync.js +26 -19
  44. package/dist/repo/index.d.ts +1 -0
  45. package/dist/repo/index.js +1 -0
  46. package/dist/util/index.d.ts +0 -6
  47. package/dist/util/index.js +0 -6
  48. package/lib/models/{content/ArrayView.ts → ArrayView.ts} +2 -2
  49. package/lib/models/BayesianScore.ts +32 -0
  50. package/lib/models/{markup/ChangeModel.ts → ChangeModel.ts} +3 -4
  51. package/lib/models/{content/Content.ts → Content.ts} +15 -18
  52. package/lib/models/{content/ContentKind.ts → ContentKind.ts} +6 -1
  53. package/lib/models/{content/Device.ts → Device.ts} +26 -22
  54. package/lib/models/Hanzi.ts +16 -0
  55. package/lib/models/{content/Manifest.ts → Manifest.ts} +15 -6
  56. package/lib/models/{content/Media.ts → Media.ts} +3 -4
  57. package/lib/models/Metric.ts +233 -0
  58. package/lib/models/{content/Model.ts → Model.ts} +4 -6
  59. package/lib/models/{markup/Operation.ts → Operation.ts} +6 -16
  60. package/lib/models/{content/Permissions.ts → Permissions.ts} +0 -2
  61. package/lib/models/Phrase.ts +53 -0
  62. package/lib/models/{content/Profile.ts → Profile.ts} +4 -6
  63. package/lib/models/Progress.ts +66 -0
  64. package/lib/models/Review.ts +18 -0
  65. package/lib/models/Session.ts +140 -0
  66. package/lib/models/Term.ts +139 -0
  67. package/lib/models/User.ts +97 -0
  68. package/lib/models/Workspace.ts +129 -0
  69. package/lib/models/index.ts +22 -2
  70. package/lib/repo/ShareSync.ts +9 -13
  71. package/lib/repo/index.ts +1 -0
  72. package/lib/util/index.ts +0 -6
  73. package/package.json +4 -15
  74. package/dist/models/OutboundMessage.d.ts +0 -18
  75. package/dist/models/OutboundMessage.js +0 -25
  76. package/dist/models/content/Activity.d.ts +0 -10
  77. package/dist/models/content/Billing.d.ts +0 -144
  78. package/dist/models/content/Billing.js +0 -418
  79. package/dist/models/content/Book.d.ts +0 -77
  80. package/dist/models/content/Book.js +0 -407
  81. package/dist/models/content/Category.d.ts +0 -16
  82. package/dist/models/content/Category.js +0 -20
  83. package/dist/models/content/Checkpointable.d.ts +0 -21
  84. package/dist/models/content/Checkpointable.js +0 -156
  85. package/dist/models/content/Comment.d.ts +0 -19
  86. package/dist/models/content/Comment.js +0 -53
  87. package/dist/models/content/ConceptArt.d.ts +0 -31
  88. package/dist/models/content/ConceptArt.js +0 -84
  89. package/dist/models/content/Context.d.ts +0 -28
  90. package/dist/models/content/Context.js +0 -162
  91. package/dist/models/content/DevEnv.d.ts +0 -5
  92. package/dist/models/content/DevEnv.js +0 -9
  93. package/dist/models/content/Dictionary.d.ts +0 -31
  94. package/dist/models/content/Dictionary.js +0 -5
  95. package/dist/models/content/DictionaryEntry.d.ts +0 -20
  96. package/dist/models/content/DictionaryEntry.js +0 -2
  97. package/dist/models/content/ElasticModel.d.ts +0 -149
  98. package/dist/models/content/ElasticModel.js +0 -179
  99. package/dist/models/content/Environment.d.ts +0 -61
  100. package/dist/models/content/Environment.js +0 -124
  101. package/dist/models/content/ExportOptions.d.ts +0 -64
  102. package/dist/models/content/ExportOptions.js +0 -213
  103. package/dist/models/content/Folder.d.ts +0 -16
  104. package/dist/models/content/Folder.js +0 -33
  105. package/dist/models/content/Fragment.d.ts +0 -54
  106. package/dist/models/content/Fragment.js +0 -181
  107. package/dist/models/content/Hanzi.d.ts +0 -21
  108. package/dist/models/content/HighlightRule.d.ts +0 -9
  109. package/dist/models/content/HighlightRule.js +0 -2
  110. package/dist/models/content/Migration.d.ts +0 -68
  111. package/dist/models/content/Migration.js +0 -155
  112. package/dist/models/content/Phrase.d.ts +0 -8
  113. package/dist/models/content/Placeholder.d.ts +0 -8
  114. package/dist/models/content/Placeholder.js +0 -36
  115. package/dist/models/content/RichText.d.ts +0 -58
  116. package/dist/models/content/RichText.js +0 -79
  117. package/dist/models/content/Session.js +0 -173
  118. package/dist/models/content/Speech.d.ts +0 -67
  119. package/dist/models/content/Speech.js +0 -97
  120. package/dist/models/content/Stub.d.ts +0 -24
  121. package/dist/models/content/Stub.js +0 -179
  122. package/dist/models/content/Time.d.ts +0 -56
  123. package/dist/models/content/Time.js +0 -295
  124. package/dist/models/content/User.d.ts +0 -36
  125. package/dist/models/content/User.js +0 -95
  126. package/dist/models/content/Workspace.d.ts +0 -71
  127. package/dist/models/content/Workspace.js +0 -237
  128. package/dist/models/content/index.d.ts +0 -17
  129. package/dist/models/content/index.js +0 -34
  130. package/dist/models/legacy/LegacyBodyFormat.d.ts +0 -9
  131. package/dist/models/legacy/LegacyBodyFormat.js +0 -2
  132. package/dist/models/legacy/LegacyComment.d.ts +0 -12
  133. package/dist/models/legacy/LegacyComment.js +0 -2
  134. package/dist/models/legacy/LegacyContent.d.ts +0 -53
  135. package/dist/models/legacy/LegacyContent.js +0 -55
  136. package/dist/models/legacy/LegacyConversion.d.ts +0 -55
  137. package/dist/models/legacy/LegacyConversion.js +0 -401
  138. package/dist/models/legacy/LegacyFragment.d.ts +0 -21
  139. package/dist/models/legacy/LegacyFragment.js +0 -2
  140. package/dist/models/legacy/LegacyLocator.d.ts +0 -8
  141. package/dist/models/legacy/LegacyLocator.js +0 -31
  142. package/dist/models/legacy/LegacyOutboundMessage.d.ts +0 -16
  143. package/dist/models/legacy/LegacyOutboundMessage.js +0 -13
  144. package/dist/models/legacy/LegacyPicture.d.ts +0 -14
  145. package/dist/models/legacy/LegacyPicture.js +0 -2
  146. package/dist/models/legacy/LegacyProfile.d.ts +0 -9
  147. package/dist/models/legacy/LegacyProfile.js +0 -2
  148. package/dist/models/legacy/LegacySession.d.ts +0 -41
  149. package/dist/models/legacy/LegacySession.js +0 -35
  150. package/dist/models/legacy/LegacyStory.d.ts +0 -23
  151. package/dist/models/legacy/LegacyStory.js +0 -2
  152. package/dist/models/legacy/LegacyStub.d.ts +0 -15
  153. package/dist/models/legacy/LegacyStub.js +0 -2
  154. package/dist/models/legacy/LegacyTransaction.d.ts +0 -14
  155. package/dist/models/legacy/LegacyTransaction.js +0 -49
  156. package/dist/models/legacy/LegacyUser.d.ts +0 -28
  157. package/dist/models/legacy/LegacyUser.js +0 -32
  158. package/dist/models/legacy/LegacyWorkspace.d.ts +0 -23
  159. package/dist/models/legacy/LegacyWorkspace.js +0 -6
  160. package/dist/models/legacy/index.d.ts +0 -15
  161. package/dist/models/legacy/index.js +0 -32
  162. package/dist/models/markup/BodyFormat.d.ts +0 -14
  163. package/dist/models/markup/BodyFormat.js +0 -190
  164. package/dist/models/markup/DeltaOps.d.ts +0 -5
  165. package/dist/models/markup/DeltaOps.js +0 -74
  166. package/dist/models/markup/HtmlMarkup.d.ts +0 -4
  167. package/dist/models/markup/HtmlMarkup.js +0 -21
  168. package/dist/models/markup/index.d.ts +0 -4
  169. package/dist/models/markup/index.js +0 -21
  170. package/dist/util/Async.d.ts +0 -8
  171. package/dist/util/Async.js +0 -18
  172. package/dist/util/Base62.d.ts +0 -6
  173. package/dist/util/Base62.js +0 -47
  174. package/dist/util/BinarySearch.d.ts +0 -7
  175. package/dist/util/BinarySearch.js +0 -46
  176. package/dist/util/CachingHasher.d.ts +0 -8
  177. package/dist/util/CachingHasher.js +0 -41
  178. package/dist/util/Color.d.ts +0 -32
  179. package/dist/util/Color.js +0 -204
  180. package/dist/util/Dispatch.d.ts +0 -15
  181. package/dist/util/Dispatch.js +0 -79
  182. package/dist/util/EditDistance.d.ts +0 -13
  183. package/dist/util/EditDistance.js +0 -184
  184. package/dist/util/NumberFormat.d.ts +0 -14
  185. package/dist/util/NumberFormat.js +0 -224
  186. package/dist/util/Struct.d.ts +0 -4
  187. package/dist/util/Struct.js +0 -15
  188. package/dist/util/Template.d.ts +0 -16
  189. package/dist/util/Template.js +0 -128
  190. package/dist/util/Text.d.ts +0 -45
  191. package/dist/util/Text.js +0 -243
  192. package/dist/util/Tuples.d.ts +0 -9
  193. package/dist/util/Tuples.js +0 -135
  194. package/dist/util/Validate.d.ts +0 -4
  195. package/dist/util/Validate.js +0 -11
  196. package/dist/util/Vocabulary.d.ts +0 -3
  197. package/dist/util/Vocabulary.js +0 -35
  198. package/lib/models/content/Billing.ts +0 -558
  199. package/lib/models/content/DevEnv.ts +0 -5
  200. package/lib/models/content/DictionaryEntry.ts +0 -22
  201. package/lib/models/content/Hanzi.ts +0 -25
  202. package/lib/models/content/Phrase.ts +0 -10
  203. package/lib/models/content/Time.ts +0 -328
  204. package/lib/models/content/User.ts +0 -130
  205. package/lib/models/content/index.ts +0 -19
  206. package/lib/models/markup/DeltaOps.ts +0 -71
  207. package/lib/models/markup/index.ts +0 -6
  208. package/lib/util/Base62.ts +0 -47
  209. package/lib/util/CachingHasher.ts +0 -38
  210. package/lib/util/Dispatch.ts +0 -92
  211. package/lib/util/NumberFormat.ts +0 -194
  212. package/lib/util/Struct.ts +0 -14
  213. package/lib/util/Tuples.ts +0 -131
  214. /package/dist/models/{content/GeoLocation.d.ts → GeoLocation.d.ts} +0 -0
  215. /package/dist/models/{content/GeoLocation.js → GeoLocation.js} +0 -0
  216. /package/dist/models/{content/Hanzi.js → Hanzi.js} +0 -0
  217. /package/dist/models/{content/Permissions.d.ts → Permissions.d.ts} +0 -0
  218. /package/dist/models/{content/Permissions.js → Permissions.js} +0 -0
  219. /package/dist/models/{content/Phrase.js → Phrase.js} +0 -0
  220. /package/dist/models/{content/Activity.js → Review.js} +0 -0
  221. /package/dist/{models/markup → repo}/TextEditOps.d.ts +0 -0
  222. /package/dist/{models/markup → repo}/TextEditOps.js +0 -0
  223. /package/lib/models/{content/GeoLocation.ts → GeoLocation.ts} +0 -0
  224. /package/lib/{models/markup → repo}/TextEditOps.ts +0 -0
@@ -1,156 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Checkpointable = void 0;
4
- const util_1 = require("../../util");
5
- const Operation_1 = require("../markup/Operation");
6
- const ArrayView_1 = require("./ArrayView");
7
- const Content_1 = require("./Content");
8
- const Time_1 = require("./Time");
9
- class Checkpointable extends Content_1.Content {
10
- constructor(doc, shouldAcquire, shareSync) {
11
- super(doc, shouldAcquire, shareSync);
12
- this._checkpointsView = null;
13
- this._checkpointsView = new ArrayView_1.ArrayView(this, ['meta', 'checkpoints']);
14
- }
15
- get checkpoints() {
16
- this.checkDisposed("Content.checkpoints");
17
- return this._checkpointsView;
18
- }
19
- hasCheckpoint(timestamp) {
20
- this.checkDisposed("Content.hasCheckpoint");
21
- let result = util_1.BinarySearch.ofDateTimes(timestamp, this.meta.checkpoints);
22
- return result >= 0;
23
- }
24
- addCheckpoint(timestamp) {
25
- this.checkDisposed("Content.addCheckpoint");
26
- // We always want to add the new checkpoint at the correctly-sorted index.
27
- let result = util_1.BinarySearch.ofDateTimes(timestamp, this.meta.checkpoints);
28
- if (result >= 0) {
29
- // This checkpoint timestamp is already recorded. Don't add it again.
30
- return false;
31
- }
32
- let insertionPoint = -(result + 1);
33
- this.checkpoints.insert(insertionPoint, timestamp);
34
- return true;
35
- }
36
- makeCheckpointBody() {
37
- this.checkDisposed("Checkpointable.makeCheckpointBody");
38
- const body = this.cloneContentBody();
39
- if (body && body.meta) {
40
- body.meta.is_head = false;
41
- body.meta.created_at = util_1.Struct.clone(body.meta.updated_at);
42
- body.meta.ref = Content_1.Content.makeContentRef(body.meta.id, body.meta.updated_at.utc_time);
43
- if (body.meta.hasOwnProperty('checkpoints')) {
44
- delete body.meta.checkpoints;
45
- }
46
- }
47
- return body;
48
- }
49
- cloneCheckpoints() {
50
- this.checkDisposed("Checkpointable.cloneCheckpoints");
51
- if (this.meta.checkpoints) {
52
- return util_1.Struct.clone(this.meta.checkpoints);
53
- }
54
- else {
55
- return null;
56
- }
57
- }
58
- recordCheckpoint(checkpointBody) {
59
- this.checkDisposed("Checkpointable.recordCheckpoint");
60
- // Don't take new checkpoints for timestamps that have already been checkpointed.
61
- let checkpointTimestamp = checkpointBody.meta.created_at.utc_time;
62
- if (!this.hasCheckpoint(checkpointTimestamp)) {
63
- // Record the new checkpoint content
64
- const checkpoint = this.shareSync.createContent(checkpointBody);
65
- checkpoint.release();
66
- // Add a new timestamp entry to the checkpoints array
67
- this._checkpointsView.push(checkpointTimestamp);
68
- }
69
- }
70
- async acquireLastCheckpoint() {
71
- if (this.meta.checkpoints && this.meta.checkpoints.length > 0) {
72
- let checkpoints = this.cloneCheckpoints().sort();
73
- const latestCheckpointTimestamp = checkpoints[checkpoints.length - 1];
74
- const latestCheckpointRef = Content_1.Content.makeContentRef(this.id, latestCheckpointTimestamp);
75
- const checkpoint = await this.shareSync.acquire(this.kind, latestCheckpointRef);
76
- return checkpoint;
77
- }
78
- return null;
79
- }
80
- async acquireLatestCheckpointAt(timestamp) {
81
- let checkpoint = await this.loadLatestCheckpointAt(timestamp);
82
- checkpoint = await checkpoint.acquire();
83
- return checkpoint;
84
- }
85
- async loadLatestCheckpointAt(timestamp) {
86
- this.checkDisposed("Checkpointable.findLatestCheckpointAt");
87
- // To search through checkpoints, we need to make sure we're looking at the HEAD version.
88
- if (this.isCheckpoint) {
89
- const head = await this.shareSync.acquire(this.kind, this.id);
90
- const latestCheckpoint = await head.loadLatestCheckpointAt(timestamp);
91
- head.release();
92
- return latestCheckpoint;
93
- }
94
- // First, check to see if the HEAD version of this content might be the "latest checkpoint".
95
- if (Time_1.Time.isDateTimeBefore(this.updatedAt.utc_time, timestamp)) {
96
- return this;
97
- }
98
- // The HEAD version is not the latest checkpoint at the given timestamp. Try to find an actual checkpoint.
99
- let checkpoints = this.cloneCheckpoints();
100
- if (checkpoints) {
101
- // Sort the checkpoints array in ascending order (oldest checkpoints are first).
102
- checkpoints.sort();
103
- // Use binary-search to find this timestamp
104
- let idx = util_1.BinarySearch.ofDateTimes(timestamp, checkpoints);
105
- // If the resut is negative, then it's an insertion-point...
106
- if (idx < 0) {
107
- // Convert the result into an insertion point.
108
- let insertionPoint = -(idx + 1);
109
- // Insertion points always represent the position AFTER the first element that's LESS THAN this element.
110
- // So to find the checkpoint that was active at the designated timestamp, we need to find the position
111
- // BEFORE this insertion point. But if the insertion point is ZERO, then there is no such checkpoint...
112
- if (insertionPoint == 0) {
113
- return null;
114
- }
115
- idx = insertionPoint - 1;
116
- }
117
- const checkpointTimestamp = checkpoints[idx];
118
- const checkpointRef = Content_1.Content.makeContentRef(this.id, checkpointTimestamp);
119
- const checkpoint = await this.shareSync.acquire(this.kind, checkpointRef);
120
- return checkpoint;
121
- }
122
- return this;
123
- }
124
- async beforeRestoreTo(checkpoint, now) {
125
- this.checkDisposed("Checkpointable.beforeRestoreTo");
126
- // By default, do nothing. Subclasses can override this behavior, if they choose.
127
- }
128
- async restoreTo(checkpoint, now) {
129
- this.checkDisposed("Checkpointable.restoreTo");
130
- if (this.isCheckpoint || checkpoint.kind != this.kind || checkpoint.id !== this.id) {
131
- throw new Error(`can't restore checkpoint ${checkpoint.kind}/${checkpoint.ref} into ${this.kind}/${this.ref}`);
132
- }
133
- // Ensure that the data in the head model has been populated.
134
- await this.ensureData();
135
- // Call any kind-specific logic preceeding the restoration. For example, a Fragment
136
- // might need to restore embedded Comments before restoring the Fragment itself.
137
- await this.beforeRestoreTo(checkpoint, now);
138
- // We need to make sure the current HEAD state is recorded as a checkpoint. If the most-recent
139
- // checkpoint has the same payload as the head, then we can skip recording a new checkpoint.
140
- let lastCheckpointPayload = null;
141
- const lastCheckpoint = await this.acquireLastCheckpoint();
142
- if (lastCheckpoint !== null) {
143
- lastCheckpointPayload = lastCheckpoint.payload;
144
- lastCheckpoint.release();
145
- }
146
- if (!util_1.Struct.equals(lastCheckpointPayload, this.payload)) {
147
- const checkpointBody = this.makeCheckpointBody();
148
- this.recordCheckpoint(checkpointBody);
149
- }
150
- // Replace the current payload with the payload from the selected checkpoint.
151
- let batch = new Operation_1.BatchOperation(this, now);
152
- batch.setPathValue(['payload'], util_1.Struct.clone(checkpoint.payload));
153
- batch.commit();
154
- }
155
- }
156
- exports.Checkpointable = Checkpointable;
@@ -1,19 +0,0 @@
1
- /// <reference path="../../../decs.d.ts" />
2
- import { Doc } from '@shaxpir/sharedb/lib/client';
3
- import { ShareSync } from '../../repo/ShareSync';
4
- import { ContentBody, ContentId, ContentMeta, ContentRef } from './Content';
5
- import { RichText, RichTextPayload } from './RichText';
6
- export interface CommentPayload extends RichTextPayload {
7
- anchor: ContentRef;
8
- }
9
- export interface CommentBody extends ContentBody {
10
- meta: ContentMeta;
11
- payload: CommentPayload;
12
- }
13
- export declare class Comment extends RichText {
14
- static create(userId: ContentId, anchorContentRef: ContentRef): Comment;
15
- constructor(doc: Doc, shouldAcquire: boolean, shareSync: ShareSync);
16
- get payload(): CommentPayload;
17
- get anchor(): ContentRef;
18
- setAnchor(value: ContentRef): void;
19
- }
@@ -1,53 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Comment = void 0;
4
- const ShareSync_1 = require("../../repo/ShareSync");
5
- const Operation_1 = require("../markup/Operation");
6
- const ContentKind_1 = require("./ContentKind");
7
- const RichText_1 = require("./RichText");
8
- const Time_1 = require("./Time");
9
- class Comment extends RichText_1.RichText {
10
- static create(userId, anchorContentRef) {
11
- const now = Time_1.MultiClock.now();
12
- const shareSync = ShareSync_1.ShareSyncFactory.get();
13
- const commentId = shareSync.makeContentId();
14
- return shareSync.createContent({
15
- meta: {
16
- ref: commentId,
17
- is_head: true,
18
- kind: ContentKind_1.ContentKind.COMMENT,
19
- id: commentId,
20
- owner: userId,
21
- created_at: now,
22
- updated_at: now,
23
- checkpoints: []
24
- },
25
- payload: {
26
- anchor: anchorContentRef,
27
- richtext_flavor: RichText_1.RichTextFlavor.quill,
28
- richtext_body: { ops: [] },
29
- word_count: 0
30
- }
31
- });
32
- }
33
- constructor(doc, shouldAcquire, shareSync) {
34
- super(doc, shouldAcquire, shareSync);
35
- }
36
- get payload() {
37
- this.checkDisposed("Comment.payload");
38
- return this.doc.data.payload;
39
- }
40
- get anchor() {
41
- this.checkDisposed("Comment.anchor");
42
- return this.payload.anchor;
43
- }
44
- setAnchor(value) {
45
- this.checkDisposed("Comment.setAnchor");
46
- if (this.anchor !== value) {
47
- const batch = new Operation_1.BatchOperation(this);
48
- batch.setPathValue(['payload', 'anchor'], value);
49
- batch.commit();
50
- }
51
- }
52
- }
53
- exports.Comment = Comment;
@@ -1,31 +0,0 @@
1
- /// <reference path="../../../decs.d.ts" />
2
- import { Doc } from '@shaxpir/sharedb/lib/client';
3
- import { ShareSync } from '../../repo/ShareSync';
4
- import { ArrayView } from './ArrayView';
5
- import { ContentBody, ContentId, ContentMeta, ContentRef } from './Content';
6
- import { MediaCropping } from './Media';
7
- import { RichText, RichTextPayload } from './RichText';
8
- export interface ConceptArtPayload extends RichTextPayload {
9
- name: string;
10
- media_ref: ContentRef;
11
- references: ContentRef[];
12
- cropping: MediaCropping;
13
- }
14
- export interface ConceptArtBody extends ContentBody {
15
- meta: ContentMeta;
16
- payload: ConceptArtPayload;
17
- }
18
- export declare class ConceptArt extends RichText {
19
- private _referencesView;
20
- constructor(doc: Doc, isCreating: boolean, shareSync: ShareSync);
21
- get payload(): ConceptArtPayload;
22
- static create(userId: ContentId, conceptArtId: ContentId, payload: ConceptArtPayload): ConceptArt;
23
- static makeConceptArtIdForMedia(mediaId: ContentId): ContentId;
24
- get name(): string;
25
- setName(value: string, newWordCount: number): void;
26
- get mediaRef(): ContentId;
27
- get cropping(): MediaCropping;
28
- setCropping(value: MediaCropping): void;
29
- get references(): ArrayView<ContentRef>;
30
- updateReferrer(referrerRef: ContentRef): Promise<void>;
31
- }
@@ -1,84 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ConceptArt = void 0;
4
- const ShareSync_1 = require("../../repo/ShareSync");
5
- const CachingHasher_1 = require("../../util/CachingHasher");
6
- const Operation_1 = require("../markup/Operation");
7
- const ArrayView_1 = require("./ArrayView");
8
- const ContentKind_1 = require("./ContentKind");
9
- const RichText_1 = require("./RichText");
10
- const Time_1 = require("./Time");
11
- class ConceptArt extends RichText_1.RichText {
12
- constructor(doc, isCreating, shareSync) {
13
- super(doc, isCreating, shareSync);
14
- this._referencesView = new ArrayView_1.ArrayView(this, ['payload', 'references']);
15
- }
16
- get payload() {
17
- this.checkDisposed("ConceptArt.payload");
18
- return this.doc.data.payload;
19
- }
20
- static create(userId, conceptArtId, payload) {
21
- const now = Time_1.MultiClock.now();
22
- return ShareSync_1.ShareSyncFactory.get().createContent({
23
- meta: {
24
- ref: conceptArtId,
25
- is_head: true,
26
- kind: ContentKind_1.ContentKind.CONCEPT_ART,
27
- id: conceptArtId,
28
- owner: userId,
29
- created_at: now,
30
- updated_at: now,
31
- checkpoints: []
32
- },
33
- payload: payload
34
- });
35
- }
36
- static makeConceptArtIdForMedia(mediaId) {
37
- return CachingHasher_1.CachingHasher.makeMd5ContentId(mediaId + "-" + ContentKind_1.ContentKind.CONCEPT_ART);
38
- }
39
- get name() {
40
- this.checkDisposed("ConceptArt.name");
41
- return this.payload.name;
42
- }
43
- setName(value, newWordCount) {
44
- this.checkDisposed("ConceptArt.setName");
45
- if (this.name != value) {
46
- const batch = new Operation_1.BatchOperation(this);
47
- batch.editPathText(['payload', 'name'], value);
48
- if (this.wordCount != newWordCount) {
49
- batch.setPathValue(['payload', 'word_count'], newWordCount);
50
- }
51
- batch.commit();
52
- }
53
- }
54
- get mediaRef() {
55
- this.checkDisposed("ConceptArt.mediaRef");
56
- return this.payload.media_ref;
57
- }
58
- get cropping() {
59
- this.checkDisposed("ConceptArt.cropping");
60
- return this.payload.cropping;
61
- }
62
- setCropping(value) {
63
- this.checkDisposed("ConceptArt.setCropping");
64
- if (this.cropping !== value) {
65
- const batch = new Operation_1.BatchOperation(this);
66
- batch.setPathValue(['payload', 'cropping'], value);
67
- batch.commit();
68
- }
69
- }
70
- get references() {
71
- this.checkDisposed("ConceptArt.references");
72
- return this._referencesView;
73
- }
74
- async updateReferrer(referrerRef) {
75
- this.checkDisposed("ConceptArt.updateReferrer");
76
- const shareSync = ShareSync_1.ShareSyncFactory.get();
77
- const fragment = await shareSync.acquire(ContentKind_1.ContentKind.FRAGMENT, referrerRef);
78
- if (fragment.gallery.indexOf(this.id) < 0) {
79
- fragment.gallery.push(this.id);
80
- }
81
- fragment.release();
82
- }
83
- }
84
- exports.ConceptArt = ConceptArt;
@@ -1,28 +0,0 @@
1
- /// <reference path="../../../decs.d.ts" />
2
- import { Doc } from '@shaxpir/sharedb/lib/client';
3
- import { ShareSync } from '../../repo/ShareSync';
4
- import { JsonPath } from '../markup/Operation';
5
- import { ArrayView } from './ArrayView';
6
- import { BookPayload, BookStubArrayKey } from './Book';
7
- import { Content, ContentBody, ContentId, ContentMeta, ContentRef } from "./Content";
8
- import { Stub } from "./Stub";
9
- import { WorkspacePayload, WorkspaceStubArrayKey } from './Workspace';
10
- export type StubArrayKey = BookStubArrayKey | WorkspaceStubArrayKey;
11
- export interface ContextBody extends ContentBody {
12
- meta: ContentMeta;
13
- payload: WorkspacePayload | BookPayload;
14
- }
15
- export declare abstract class Context extends Content {
16
- protected _trashView: ArrayView<Stub>;
17
- constructor(doc: Doc, shouldAcquire: boolean, shareSync: ShareSync);
18
- get trash(): ArrayView<Stub>;
19
- abstract getStubArrayKeys(): StubArrayKey[];
20
- abstract getStubArrayView(key: StubArrayKey): ArrayView<Stub>;
21
- findPathToStub(ref: ContentRef): JsonPath;
22
- removeStubAtPath(path: JsonPath, moveToTrash: boolean): void;
23
- getStubAtPath(path: JsonPath): Stub;
24
- setStubFieldValue(ref: ContentRef, fieldName: string, value: any): void;
25
- editStubFieldText(ref: ContentRef, fieldName: string, value: string): void;
26
- addFolder(stub: Stub, key: StubArrayKey, activeId?: ContentId): void;
27
- mergeIncomingContext(incomingContextBody: ContextBody): boolean;
28
- }
@@ -1,162 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Context = void 0;
4
- const Struct_1 = require("../../util/Struct");
5
- const Operation_1 = require("../markup/Operation");
6
- const ArrayView_1 = require("./ArrayView");
7
- const Content_1 = require("./Content");
8
- const Stub_1 = require("./Stub");
9
- class Context extends Content_1.Content {
10
- constructor(doc, shouldAcquire, shareSync) {
11
- super(doc, shouldAcquire, shareSync);
12
- this._trashView = new ArrayView_1.ArrayView(this, ['payload', 'trash']);
13
- }
14
- get trash() {
15
- this.checkDisposed("Context.trash");
16
- return this._trashView;
17
- }
18
- findPathToStub(ref) {
19
- this.checkDisposed("Context.findPathToStub");
20
- const arrayKeys = this.getStubArrayKeys();
21
- for (let i = 0, len = arrayKeys.length; i < len; i++) {
22
- const key = arrayKeys[i];
23
- const view = this.getStubArrayView(key);
24
- if (view) {
25
- const index = view.firstIndexWhere((stub) => {
26
- return (Stub_1.Stubs.isContentStub(stub) && stub.ref == ref)
27
- || (Stub_1.Stubs.isFolderStub(stub) && stub.id == ref);
28
- });
29
- if (index >= 0) {
30
- return ['payload', key, index];
31
- }
32
- }
33
- }
34
- return null;
35
- }
36
- removeStubAtPath(path, moveToTrash) {
37
- this.checkDisposed("Context.removeStubAtPath");
38
- // Make sure this stub isn't already in the trash
39
- const stubArrayKey = path[1];
40
- if (stubArrayKey === "trash") {
41
- return;
42
- }
43
- // If the stub has a parent, take note of it, so that we can reassign parentage for all orphans or the removed stub.
44
- const stubToDelete = this.getStubAtPath(path);
45
- const stubIdToDelete = Stub_1.Stubs.idFromStub(stubToDelete);
46
- const grandparentId = stubToDelete.parent;
47
- const batch = new Operation_1.BatchOperation(this);
48
- // Reparent all stubs that previously referred to this stub as their parent.
49
- // If this stub has no parent, then remove the parent property from all of its children.
50
- const stubArrayView = this.getStubArrayView(stubArrayKey);
51
- for (let i = 0, len = stubArrayView.length; i < len; i++) {
52
- const stub = stubArrayView.get(i);
53
- if (stub.parent === stubIdToDelete) {
54
- const pathToParentProperty = ['payload', stubArrayKey, i, 'parent'];
55
- if (grandparentId) {
56
- batch.replaceValueAtPath(pathToParentProperty, grandparentId);
57
- }
58
- else {
59
- batch.removeValueAtPath(pathToParentProperty);
60
- }
61
- }
62
- }
63
- // Remove the parentage of the deleted stub
64
- if (grandparentId) {
65
- const pathToParentProperty = Struct_1.Struct.clone(path);
66
- pathToParentProperty.push('parent');
67
- batch.removeValueAtPath(pathToParentProperty);
68
- }
69
- // Finally, either remove the deleted stub entirely, or move it to the trash.
70
- if (moveToTrash) {
71
- const trashStubCount = this._trashView.length;
72
- batch.move(path, ['payload', 'trash', trashStubCount]);
73
- }
74
- else {
75
- batch.removeValueAtPath(path);
76
- }
77
- batch.commit();
78
- }
79
- getStubAtPath(path) {
80
- this.checkDisposed("Context.getStubAtPath");
81
- return Operation_1.JsonPathSelect.getValueAtPath(this.doc, path);
82
- }
83
- setStubFieldValue(ref, fieldName, value) {
84
- this.checkDisposed("Context.setStubFieldValue");
85
- const path = this.findPathToStub(ref);
86
- if (fieldName !== 'label' && fieldName != 'category') {
87
- throw new Error(`setting unexpected fieldName '${fieldName}' to value ${JSON.stringify(value)}`);
88
- }
89
- if (path !== null) {
90
- path.push(fieldName);
91
- const batch = new Operation_1.BatchOperation(this);
92
- batch.setPathValue(path, value);
93
- batch.commit();
94
- }
95
- }
96
- editStubFieldText(ref, fieldName, value) {
97
- this.checkDisposed("Context.setStubFieldValue");
98
- const path = this.findPathToStub(ref);
99
- if (fieldName !== 'label' && fieldName != 'category') {
100
- throw new Error(`setting unexpected fieldName '${fieldName}' to value '${value}'`);
101
- }
102
- if (path !== null) {
103
- path.push(fieldName);
104
- const batch = new Operation_1.BatchOperation(this);
105
- batch.editPathText(path, value);
106
- batch.commit();
107
- }
108
- }
109
- addFolder(stub, key, activeId) {
110
- this.checkDisposed("Context.addFolder");
111
- const stubArrayView = this.getStubArrayView(key);
112
- Stub_1.Stubs.insertStubAtActivePoint(stub, stubArrayView, null, activeId, false);
113
- }
114
- mergeIncomingContext(incomingContextBody) {
115
- let madeChanges = false;
116
- // First, gather all the refs in this context, so that we can find any new incoming
117
- // stubs that might need to be merged. It's important that we look through all potential
118
- // stub arrays, because any individual stub may have been moved between arrays. We only
119
- // want to merge in new stubs if they don't already exist anywhere in this context.
120
- const stubIds = new Set();
121
- const stubArrayKeys = this.getStubArrayKeys();
122
- for (let i = 0; i < stubArrayKeys.length; i++) {
123
- const stubArrayKey = stubArrayKeys[i];
124
- const stubArrayView = this.getStubArrayView(stubArrayKey);
125
- stubArrayView.forEach((idx, stub) => {
126
- stubIds.add(Stub_1.Stubs.idFromStub(stub));
127
- });
128
- }
129
- // Next, merge in any new stubs from the incoming context.
130
- const incomingPayload = incomingContextBody.payload;
131
- for (let i = 0; i < stubArrayKeys.length; i++) {
132
- const stubArrayKey = stubArrayKeys[i];
133
- const stubArrayView = this.getStubArrayView(stubArrayKey);
134
- if (incomingPayload.hasOwnProperty(stubArrayKey)) {
135
- const incomingStubArray = incomingPayload[stubArrayKey];
136
- for (let j = 0; j < incomingStubArray.length; j++) {
137
- const incomingStub = incomingStubArray[j];
138
- const incomingStubId = Stub_1.Stubs.idFromStub(incomingStub);
139
- if (!stubIds.has(incomingStubId)) {
140
- // This stub is not currently present in this context, so merge it in. We will
141
- // attempt to add it to the corrent position in the array, but it's possible
142
- // that the array has been reordered, so insertion of this stub might not be in
143
- // quite the right position. But we're just trying to make sure that the stubs
144
- // are all present, and this capabililty is only being included as a way of
145
- // recovering from a migration bug that only affected a small number of users.
146
- if (j < stubArrayView.length) {
147
- stubArrayView.insert(j, incomingStub);
148
- }
149
- else {
150
- stubArrayView.push(incomingStub);
151
- }
152
- // Add the new stub to the set of stubs we've already seen
153
- stubIds.add(incomingStubId);
154
- madeChanges = true;
155
- }
156
- }
157
- }
158
- }
159
- return madeChanges;
160
- }
161
- }
162
- exports.Context = Context;
@@ -1,5 +0,0 @@
1
- export declare enum DevEnv {
2
- LOCAL = "LOCAL",
3
- STAGING = "STAGING",
4
- PRODUCTION = "PRODUCTION"
5
- }
@@ -1,9 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DevEnv = void 0;
4
- var DevEnv;
5
- (function (DevEnv) {
6
- DevEnv["LOCAL"] = "LOCAL";
7
- DevEnv["STAGING"] = "STAGING";
8
- DevEnv["PRODUCTION"] = "PRODUCTION";
9
- })(DevEnv || (exports.DevEnv = DevEnv = {}));
@@ -1,31 +0,0 @@
1
- import { ContentMeta } from "./Content";
2
- declare enum DictionaryIdBrand {
3
- }
4
- export type DictionaryId = (string & DictionaryIdBrand) | null;
5
- export interface DictionaryEntry {
6
- text: string;
7
- repl?: string;
8
- freq?: number;
9
- score?: number;
10
- phon?: string;
11
- }
12
- export interface ResolvedDictionary {
13
- entries: {
14
- [key: string]: DictionaryEntry;
15
- };
16
- }
17
- export interface DictionaryBody {
18
- meta: ContentMeta;
19
- payload: DictionaryPayload;
20
- }
21
- export interface DictionaryPayload {
22
- id: string;
23
- name: string;
24
- include_dicts: DictionaryId[];
25
- exclude_keys: string[];
26
- entries: DictionaryEntry[];
27
- }
28
- export interface Dictionary extends DictionaryPayload {
29
- resolved?: ResolvedDictionary;
30
- }
31
- export {};
@@ -1,5 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- var DictionaryIdBrand;
4
- (function (DictionaryIdBrand) {
5
- })(DictionaryIdBrand || (DictionaryIdBrand = {}));
@@ -1,20 +0,0 @@
1
- export interface DictionaryEntry {
2
- text: string;
3
- rank: number;
4
- learn_rank: number;
5
- is_starred?: boolean;
6
- tags: string[];
7
- }
8
- export interface Pronouncable {
9
- pinyin: string;
10
- pinyin_tokenized?: string;
11
- pinyin_normalized: string;
12
- }
13
- export interface Definable {
14
- definition: string;
15
- definition_analysis: string;
16
- translation?: string;
17
- transliteration?: string;
18
- function?: string;
19
- usage?: string;
20
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });