@shaxpir/duiduidui-models 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/decs.d.ts +87 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +20 -0
- package/dist/models/OutboundMessage.d.ts +18 -0
- package/dist/models/OutboundMessage.js +25 -0
- package/dist/models/content/Activity.d.ts +10 -0
- package/dist/models/content/Activity.js +2 -0
- package/dist/models/content/ArrayView.d.ts +26 -0
- package/dist/models/content/ArrayView.js +174 -0
- package/dist/models/content/Billing.d.ts +144 -0
- package/dist/models/content/Billing.js +418 -0
- package/dist/models/content/Book.d.ts +77 -0
- package/dist/models/content/Book.js +407 -0
- package/dist/models/content/Category.d.ts +16 -0
- package/dist/models/content/Category.js +20 -0
- package/dist/models/content/Checkpointable.d.ts +21 -0
- package/dist/models/content/Checkpointable.js +156 -0
- package/dist/models/content/Comment.d.ts +19 -0
- package/dist/models/content/Comment.js +53 -0
- package/dist/models/content/ConceptArt.d.ts +31 -0
- package/dist/models/content/ConceptArt.js +84 -0
- package/dist/models/content/Content.d.ts +52 -0
- package/dist/models/content/Content.js +61 -0
- package/dist/models/content/ContentKind.d.ts +10 -0
- package/dist/models/content/ContentKind.js +16 -0
- package/dist/models/content/Context.d.ts +28 -0
- package/dist/models/content/Context.js +162 -0
- package/dist/models/content/DevEnv.d.ts +5 -0
- package/dist/models/content/DevEnv.js +9 -0
- package/dist/models/content/Device.d.ts +24 -0
- package/dist/models/content/Device.js +62 -0
- package/dist/models/content/Dictionary.d.ts +31 -0
- package/dist/models/content/Dictionary.js +5 -0
- package/dist/models/content/DictionaryEntry.d.ts +20 -0
- package/dist/models/content/DictionaryEntry.js +2 -0
- package/dist/models/content/ElasticModel.d.ts +149 -0
- package/dist/models/content/ElasticModel.js +179 -0
- package/dist/models/content/Environment.d.ts +61 -0
- package/dist/models/content/Environment.js +124 -0
- package/dist/models/content/ExportOptions.d.ts +64 -0
- package/dist/models/content/ExportOptions.js +213 -0
- package/dist/models/content/Folder.d.ts +16 -0
- package/dist/models/content/Folder.js +33 -0
- package/dist/models/content/Fragment.d.ts +54 -0
- package/dist/models/content/Fragment.js +181 -0
- package/dist/models/content/GeoLocation.d.ts +4 -0
- package/dist/models/content/GeoLocation.js +2 -0
- package/dist/models/content/Hanzi.d.ts +21 -0
- package/dist/models/content/Hanzi.js +2 -0
- package/dist/models/content/HighlightRule.d.ts +9 -0
- package/dist/models/content/HighlightRule.js +2 -0
- package/dist/models/content/Manifest.d.ts +42 -0
- package/dist/models/content/Manifest.js +114 -0
- package/dist/models/content/Media.d.ts +32 -0
- package/dist/models/content/Media.js +98 -0
- package/dist/models/content/Metric.d.ts +46 -0
- package/dist/models/content/Metric.js +183 -0
- package/dist/models/content/Migration.d.ts +68 -0
- package/dist/models/content/Migration.js +155 -0
- package/dist/models/content/Model.d.ts +45 -0
- package/dist/models/content/Model.js +280 -0
- package/dist/models/content/Permissions.d.ts +7 -0
- package/dist/models/content/Permissions.js +20 -0
- package/dist/models/content/Phrase.d.ts +8 -0
- package/dist/models/content/Phrase.js +2 -0
- package/dist/models/content/Placeholder.d.ts +8 -0
- package/dist/models/content/Placeholder.js +36 -0
- package/dist/models/content/Profile.d.ts +30 -0
- package/dist/models/content/Profile.js +95 -0
- package/dist/models/content/RichText.d.ts +58 -0
- package/dist/models/content/RichText.js +79 -0
- package/dist/models/content/Session.d.ts +39 -0
- package/dist/models/content/Session.js +173 -0
- package/dist/models/content/Speech.d.ts +67 -0
- package/dist/models/content/Speech.js +97 -0
- package/dist/models/content/Stub.d.ts +24 -0
- package/dist/models/content/Stub.js +179 -0
- package/dist/models/content/Time.d.ts +56 -0
- package/dist/models/content/Time.js +295 -0
- package/dist/models/content/User.d.ts +36 -0
- package/dist/models/content/User.js +95 -0
- package/dist/models/content/Workspace.d.ts +71 -0
- package/dist/models/content/Workspace.js +237 -0
- package/dist/models/content/index.d.ts +36 -0
- package/dist/models/content/index.js +53 -0
- package/dist/models/index.d.ts +4 -0
- package/dist/models/index.js +21 -0
- package/dist/models/legacy/LegacyBodyFormat.d.ts +9 -0
- package/dist/models/legacy/LegacyBodyFormat.js +2 -0
- package/dist/models/legacy/LegacyComment.d.ts +12 -0
- package/dist/models/legacy/LegacyComment.js +2 -0
- package/dist/models/legacy/LegacyContent.d.ts +53 -0
- package/dist/models/legacy/LegacyContent.js +55 -0
- package/dist/models/legacy/LegacyConversion.d.ts +55 -0
- package/dist/models/legacy/LegacyConversion.js +401 -0
- package/dist/models/legacy/LegacyFragment.d.ts +21 -0
- package/dist/models/legacy/LegacyFragment.js +2 -0
- package/dist/models/legacy/LegacyLocator.d.ts +8 -0
- package/dist/models/legacy/LegacyLocator.js +31 -0
- package/dist/models/legacy/LegacyOutboundMessage.d.ts +16 -0
- package/dist/models/legacy/LegacyOutboundMessage.js +13 -0
- package/dist/models/legacy/LegacyPicture.d.ts +14 -0
- package/dist/models/legacy/LegacyPicture.js +2 -0
- package/dist/models/legacy/LegacyProfile.d.ts +9 -0
- package/dist/models/legacy/LegacyProfile.js +2 -0
- package/dist/models/legacy/LegacySession.d.ts +41 -0
- package/dist/models/legacy/LegacySession.js +35 -0
- package/dist/models/legacy/LegacyStory.d.ts +23 -0
- package/dist/models/legacy/LegacyStory.js +2 -0
- package/dist/models/legacy/LegacyStub.d.ts +15 -0
- package/dist/models/legacy/LegacyStub.js +2 -0
- package/dist/models/legacy/LegacyTransaction.d.ts +14 -0
- package/dist/models/legacy/LegacyTransaction.js +49 -0
- package/dist/models/legacy/LegacyUser.d.ts +28 -0
- package/dist/models/legacy/LegacyUser.js +32 -0
- package/dist/models/legacy/LegacyWorkspace.d.ts +23 -0
- package/dist/models/legacy/LegacyWorkspace.js +6 -0
- package/dist/models/legacy/index.d.ts +15 -0
- package/dist/models/legacy/index.js +32 -0
- package/dist/models/markup/BodyFormat.d.ts +14 -0
- package/dist/models/markup/BodyFormat.js +190 -0
- package/dist/models/markup/ChangeModel.d.ts +22 -0
- package/dist/models/markup/ChangeModel.js +107 -0
- package/dist/models/markup/DeltaOps.d.ts +5 -0
- package/dist/models/markup/DeltaOps.js +74 -0
- package/dist/models/markup/HtmlMarkup.d.ts +4 -0
- package/dist/models/markup/HtmlMarkup.js +21 -0
- package/dist/models/markup/Operation.d.ts +32 -0
- package/dist/models/markup/Operation.js +194 -0
- package/dist/models/markup/TextEditOps.d.ts +9 -0
- package/dist/models/markup/TextEditOps.js +50 -0
- package/dist/models/markup/index.d.ts +6 -0
- package/dist/models/markup/index.js +23 -0
- package/dist/repo/ConnectionListener.d.ts +9 -0
- package/dist/repo/ConnectionListener.js +21 -0
- package/dist/repo/PermissiveJson1.d.ts +58 -0
- package/dist/repo/PermissiveJson1.js +39 -0
- package/dist/repo/ShareSync.d.ts +60 -0
- package/dist/repo/ShareSync.js +348 -0
- package/dist/repo/index.d.ts +3 -0
- package/dist/repo/index.js +20 -0
- package/dist/util/Async.d.ts +8 -0
- package/dist/util/Async.js +18 -0
- package/dist/util/Base62.d.ts +6 -0
- package/dist/util/Base62.js +47 -0
- package/dist/util/BinarySearch.d.ts +7 -0
- package/dist/util/BinarySearch.js +46 -0
- package/dist/util/CachingHasher.d.ts +8 -0
- package/dist/util/CachingHasher.js +41 -0
- package/dist/util/Color.d.ts +32 -0
- package/dist/util/Color.js +204 -0
- package/dist/util/Dispatch.d.ts +15 -0
- package/dist/util/Dispatch.js +79 -0
- package/dist/util/EditDistance.d.ts +13 -0
- package/dist/util/EditDistance.js +184 -0
- package/dist/util/Encryption.d.ts +5 -0
- package/dist/util/Encryption.js +2 -0
- package/dist/util/Logging.d.ts +108 -0
- package/dist/util/Logging.js +412 -0
- package/dist/util/NumberFormat.d.ts +14 -0
- package/dist/util/NumberFormat.js +224 -0
- package/dist/util/Struct.d.ts +4 -0
- package/dist/util/Struct.js +15 -0
- package/dist/util/Template.d.ts +16 -0
- package/dist/util/Template.js +128 -0
- package/dist/util/Text.d.ts +45 -0
- package/dist/util/Text.js +243 -0
- package/dist/util/Tuples.d.ts +9 -0
- package/dist/util/Tuples.js +135 -0
- package/dist/util/Validate.d.ts +4 -0
- package/dist/util/Validate.js +11 -0
- package/dist/util/Vocabulary.d.ts +3 -0
- package/dist/util/Vocabulary.js +35 -0
- package/dist/util/index.d.ts +16 -0
- package/dist/util/index.js +33 -0
- package/lib/models/content/ArrayView.ts +203 -0
- package/lib/models/content/Billing.ts +558 -0
- package/lib/models/content/Content.ts +110 -0
- package/lib/models/content/ContentKind.ts +14 -0
- package/lib/models/content/DevEnv.ts +5 -0
- package/lib/models/content/Device.ts +86 -0
- package/lib/models/content/DictionaryEntry.ts +22 -0
- package/lib/models/content/GeoLocation.ts +4 -0
- package/lib/models/content/Hanzi.ts +25 -0
- package/lib/models/content/Manifest.ts +162 -0
- package/lib/models/content/Media.ts +126 -0
- package/lib/models/content/Model.ts +327 -0
- package/lib/models/content/Permissions.ts +21 -0
- package/lib/models/content/Phrase.ts +10 -0
- package/lib/models/content/Profile.ts +119 -0
- package/lib/models/content/Time.ts +328 -0
- package/lib/models/content/User.ts +130 -0
- package/lib/models/markup/ChangeModel.ts +95 -0
- package/lib/models/markup/DeltaOps.ts +71 -0
- package/lib/models/markup/Operation.ts +215 -0
- package/lib/models/markup/TextEditOps.ts +50 -0
- package/lib/repo/ConnectionListener.ts +25 -0
- package/lib/repo/PermissiveJson1.ts +14 -0
- package/lib/repo/ShareSync.ts +390 -0
- package/lib/util/Base62.ts +47 -0
- package/lib/util/CachingHasher.ts +38 -0
- package/lib/util/Dispatch.ts +92 -0
- package/lib/util/Encryption.ts +5 -0
- package/lib/util/Logging.ts +568 -0
- package/lib/util/NumberFormat.ts +194 -0
- package/lib/util/Struct.ts +14 -0
- package/lib/util/Tuples.ts +131 -0
- package/package.json +41 -0
- package/tsconfig.json +25 -0
- package/tslint.json +46 -0
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import { Struct } from "../../util/Struct";
|
|
2
|
+
import { BatchOperation, JsonPath, JsonPathSelect } from "../markup/Operation";
|
|
3
|
+
import { Content } from "./Content";
|
|
4
|
+
|
|
5
|
+
export class ArrayView<T> {
|
|
6
|
+
|
|
7
|
+
protected content:Content;
|
|
8
|
+
protected path:JsonPath;
|
|
9
|
+
|
|
10
|
+
constructor (content:Content, path:JsonPath) {
|
|
11
|
+
this.content = content;
|
|
12
|
+
this.path = path;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
private get root():T[] {
|
|
16
|
+
this.content.checkDisposed("ArrayView.root");
|
|
17
|
+
return JsonPathSelect.getValueAtPath(this.content.doc, this.path);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
public get length():number {
|
|
21
|
+
this.content.checkDisposed("ArrayView.length");
|
|
22
|
+
return this.root.length;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
public get values():T[] {
|
|
26
|
+
this.content.checkDisposed("ArrayView.values");
|
|
27
|
+
return Struct.clone(this.root);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
public get(idx:number):T {
|
|
31
|
+
this.content.checkDisposed("ArrayView.get");
|
|
32
|
+
return Struct.clone(this.root[idx]);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
public indexOf(value:any):number {
|
|
36
|
+
this.content.checkDisposed("ArrayView.indexOf");
|
|
37
|
+
const array:T[] = JsonPathSelect.getValueAtPath(this.content.doc, this.path);
|
|
38
|
+
for (let i:number = 0; i < array.length; i++) {
|
|
39
|
+
if (array[i] == value) {
|
|
40
|
+
return i;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return -1;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
public includes(value:any):boolean {
|
|
47
|
+
this.content.checkDisposed("ArrayView.includes");
|
|
48
|
+
const array:T[] = JsonPathSelect.getValueAtPath(this.content.doc, this.path);
|
|
49
|
+
for (let i:number = 0; i < array.length; i++) {
|
|
50
|
+
if (array[i] == value) {
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
public firstIndexWhere(
|
|
58
|
+
predicate:(value:T) => boolean
|
|
59
|
+
):number {
|
|
60
|
+
this.content.checkDisposed("ArrayView.firstIndexWhere");
|
|
61
|
+
const array:T[] = JsonPathSelect.getValueAtPath(this.content.doc, this.path);
|
|
62
|
+
for (let i:number = 0; i < array.length; i++) {
|
|
63
|
+
if (predicate(array[i])) {
|
|
64
|
+
return i;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return -1;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
public removeFirstWhere(
|
|
71
|
+
predicate:(value:T) => boolean
|
|
72
|
+
):void {
|
|
73
|
+
this.content.checkDisposed("ArrayView.removeFirstWhere");
|
|
74
|
+
const index:number = this.firstIndexWhere(predicate);
|
|
75
|
+
this.removeAt(index);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
public removeAllWhere(
|
|
79
|
+
predicate:(value:T) => boolean
|
|
80
|
+
):void {
|
|
81
|
+
this.content.checkDisposed("ArrayView.removeAllWhere");
|
|
82
|
+
let foundMatch = false;
|
|
83
|
+
const batch = new BatchOperation(this.content);
|
|
84
|
+
const array:T[] = JsonPathSelect.getValueAtPath(this.content.doc, this.path);
|
|
85
|
+
for (let i:number = 0; i < array.length; i++) {
|
|
86
|
+
if (predicate(array[i])) {
|
|
87
|
+
const pathToElement:JsonPath = Struct.clone(this.path);
|
|
88
|
+
pathToElement.push(i);
|
|
89
|
+
batch.removeValueAtPath(pathToElement);
|
|
90
|
+
foundMatch = true;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
if (foundMatch) {
|
|
94
|
+
batch.commit();
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
public forEach(
|
|
99
|
+
callback:(idx:number, value:T) => void
|
|
100
|
+
):void {
|
|
101
|
+
this.content.checkDisposed("ArrayView.forEach");
|
|
102
|
+
const array:T[] = JsonPathSelect.getValueAtPath(this.content.doc, this.path);
|
|
103
|
+
for (let i:number = 0; i < array.length; i++) {
|
|
104
|
+
callback(i, array[i]);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
public unshift(value:T):void {
|
|
109
|
+
this.content.checkDisposed("ArrayView.unshift");
|
|
110
|
+
const batch = new BatchOperation(this.content);
|
|
111
|
+
batch.unshiftIntoArray(this.path, value);
|
|
112
|
+
batch.commit();
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
public push(value:T):void {
|
|
116
|
+
this.content.checkDisposed("ArrayView.push");
|
|
117
|
+
const batch = new BatchOperation(this.content);
|
|
118
|
+
batch.pushIntoArray(this.path, value);
|
|
119
|
+
batch.commit();
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
public insert(idx:number, value:T):void {
|
|
123
|
+
this.content.checkDisposed("ArrayView.insert");
|
|
124
|
+
if (idx == this.length) {
|
|
125
|
+
this.push(value);
|
|
126
|
+
} else {
|
|
127
|
+
const batch = new BatchOperation(this.content);
|
|
128
|
+
batch.insertIntoArray(this.path, idx, value);
|
|
129
|
+
batch.commit();
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
public remove(value:T):void {
|
|
134
|
+
this.content.checkDisposed("ArrayView.remove");
|
|
135
|
+
const index:number = this.indexOf(value);
|
|
136
|
+
if (index >= 0) {
|
|
137
|
+
this.removeAt(index);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
public removeAt(index:number):void {
|
|
142
|
+
this.content.checkDisposed("ArrayView.removeAt");
|
|
143
|
+
const pathToElement:JsonPath = Struct.clone(this.path);
|
|
144
|
+
pathToElement.push(index);
|
|
145
|
+
const batch = new BatchOperation(this.content);
|
|
146
|
+
batch.removeValueAtPath(pathToElement);
|
|
147
|
+
batch.commit();
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
public move(originIndex:number, destinationIndex:number):void {
|
|
151
|
+
this.content.checkDisposed("ArrayView.move");
|
|
152
|
+
if (originIndex != destinationIndex) {
|
|
153
|
+
const originPath:JsonPath = Struct.clone(this.path);
|
|
154
|
+
const destinationPath:JsonPath = Struct.clone(this.path);
|
|
155
|
+
originPath.push(originIndex);
|
|
156
|
+
destinationPath.push(destinationIndex);
|
|
157
|
+
const batch = new BatchOperation(this.content);
|
|
158
|
+
batch.move(originPath, destinationPath);
|
|
159
|
+
batch.commit();
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
public removeObjectPropertyAtIndex(index:number, fieldName:string):void {
|
|
164
|
+
this.content.checkDisposed("ArrayView.setObjectValueAtIndex");
|
|
165
|
+
const pathToElement:JsonPath = Struct.clone(this.path);
|
|
166
|
+
pathToElement.push(index);
|
|
167
|
+
const element:any = JsonPathSelect.getValueAtPath(this.content.doc, pathToElement);
|
|
168
|
+
if (element.hasOwnProperty(fieldName)) {
|
|
169
|
+
const pathToProperty:JsonPath = Struct.clone(this.path);
|
|
170
|
+
pathToProperty.push(fieldName);
|
|
171
|
+
const batch = new BatchOperation(this.content);
|
|
172
|
+
batch.removeValueAtPath(pathToProperty)
|
|
173
|
+
batch.commit();
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
public setObjectValueAtIndex(index:number, fieldName:string, newValue:any):void {
|
|
178
|
+
this.content.checkDisposed("ArrayView.setObjectValueAtIndex");
|
|
179
|
+
const pathToElement:JsonPath = Struct.clone(this.path);
|
|
180
|
+
pathToElement.push(index);
|
|
181
|
+
pathToElement.push(fieldName);
|
|
182
|
+
const prevValue:any = JsonPathSelect.getValueAtPath(this.content.doc, pathToElement);
|
|
183
|
+
if (!Struct.equals(prevValue, newValue)) {
|
|
184
|
+
const batch = new BatchOperation(this.content);
|
|
185
|
+
batch.setPathValue(pathToElement, newValue);
|
|
186
|
+
batch.commit();
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
public editObjectTextValueAtIndex(index:number, fieldName:string, newValue:string):void {
|
|
191
|
+
this.content.checkDisposed("ArrayView.editObjectTextValueAtIndex");
|
|
192
|
+
const pathToElement:JsonPath = Struct.clone(this.path);
|
|
193
|
+
pathToElement.push(index);
|
|
194
|
+
pathToElement.push(fieldName);
|
|
195
|
+
const prevValue:any = JsonPathSelect.getValueAtPath(this.content.doc, pathToElement);
|
|
196
|
+
if (!Struct.equals(prevValue, newValue)) {
|
|
197
|
+
const batch = new BatchOperation(this.content);
|
|
198
|
+
batch.editPathText(pathToElement, newValue);
|
|
199
|
+
batch.commit();
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
}
|