@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,32 @@
|
|
|
1
|
+
/// <reference path="../../../decs.d.ts" />
|
|
2
|
+
import { Op as DeltaOp } from "@shaxpir/quill-delta";
|
|
3
|
+
import { Doc } from '@shaxpir/sharedb/lib/client';
|
|
4
|
+
import { Model } from '../content/Model';
|
|
5
|
+
import { MultiTime } from '../content/Time';
|
|
6
|
+
export type JsonPathElement = string | number;
|
|
7
|
+
export type JsonPath = JsonPathElement[];
|
|
8
|
+
export interface PathVal {
|
|
9
|
+
path: JsonPath;
|
|
10
|
+
val: any;
|
|
11
|
+
}
|
|
12
|
+
export declare class JsonPathSelect {
|
|
13
|
+
static getValueAtPath(doc: Doc, path: JsonPath): any;
|
|
14
|
+
}
|
|
15
|
+
export declare class BatchOperation {
|
|
16
|
+
private model;
|
|
17
|
+
private time;
|
|
18
|
+
private ops;
|
|
19
|
+
constructor(model: Model, time?: MultiTime);
|
|
20
|
+
get at(): MultiTime;
|
|
21
|
+
hasOps(): boolean;
|
|
22
|
+
editPathText(path: JsonPath, value: string): void;
|
|
23
|
+
setPathValue(path: JsonPath, value: any): void;
|
|
24
|
+
move(originPath: JsonPath, destinationPath: JsonPath): void;
|
|
25
|
+
insertIntoArray(arrayPath: JsonPath, index: number, value: any): void;
|
|
26
|
+
unshiftIntoArray(path: JsonPath, value: any): void;
|
|
27
|
+
pushIntoArray(path: JsonPath, value: any): void;
|
|
28
|
+
removeValueAtPath(path: JsonPath): void;
|
|
29
|
+
replaceValueAtPath(path: JsonPath, value: any): void;
|
|
30
|
+
applyRichText(path: JsonPath, deltaOps: DeltaOp[]): void;
|
|
31
|
+
commit(): void;
|
|
32
|
+
}
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.BatchOperation = exports.JsonPathSelect = void 0;
|
|
27
|
+
const ShareSync_1 = require("../../repo/ShareSync");
|
|
28
|
+
const Struct_1 = require("../../util/Struct");
|
|
29
|
+
const Content_1 = require("../content/Content");
|
|
30
|
+
const Time_1 = require("../content/Time");
|
|
31
|
+
const TextEditOps_1 = require("./TextEditOps");
|
|
32
|
+
const Json1 = __importStar(require("../../repo/PermissiveJson1"));
|
|
33
|
+
const RichText = require('@shaxpir/rich-text');
|
|
34
|
+
const UnicodeText = require('ot-text-unicode');
|
|
35
|
+
;
|
|
36
|
+
class JsonPathSelect {
|
|
37
|
+
static getValueAtPath(doc, path) {
|
|
38
|
+
let currentNode = doc.data;
|
|
39
|
+
for (let i = 0; i < path.length; i++) {
|
|
40
|
+
let pathElement = path[i];
|
|
41
|
+
if (currentNode !== undefined && currentNode !== null) {
|
|
42
|
+
if (typeof (pathElement) === "string" && currentNode.hasOwnProperty(pathElement)) {
|
|
43
|
+
currentNode = currentNode[pathElement];
|
|
44
|
+
}
|
|
45
|
+
else if (typeof (pathElement) === "number" && currentNode.length > pathElement) {
|
|
46
|
+
currentNode = currentNode[pathElement];
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
return undefined;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
console.error(`no value at path ${JSON.stringify(path)} at index ${i} in object '${doc.collection}/${doc.id}' with value ${JSON.stringify(doc.data)}`);
|
|
54
|
+
break;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return currentNode;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
exports.JsonPathSelect = JsonPathSelect;
|
|
61
|
+
class BatchOperation {
|
|
62
|
+
// TODO: maybe just use the timestamp on the Content?
|
|
63
|
+
constructor(model, time) {
|
|
64
|
+
if (model.isForbidden) {
|
|
65
|
+
throw new Error(`cannot create a BatchOperation on forbidden model: ${model.compoundKey}`);
|
|
66
|
+
}
|
|
67
|
+
this.model = model;
|
|
68
|
+
if (time) {
|
|
69
|
+
this.time = time;
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
this.time = Time_1.MultiClock.now();
|
|
73
|
+
}
|
|
74
|
+
this.ops = [];
|
|
75
|
+
}
|
|
76
|
+
get at() {
|
|
77
|
+
return Struct_1.Struct.clone(this.time);
|
|
78
|
+
}
|
|
79
|
+
hasOps() {
|
|
80
|
+
return this.ops.length > 0;
|
|
81
|
+
}
|
|
82
|
+
editPathText(path, value) {
|
|
83
|
+
const prevValue = JsonPathSelect.getValueAtPath(this.model.doc, path);
|
|
84
|
+
if (prevValue !== undefined) {
|
|
85
|
+
// If we're trying to edit a text value, but the previous value is null, then the
|
|
86
|
+
// 'editOp' will throw an exception. So we need to use a 'replaceOp' instead.
|
|
87
|
+
if (prevValue === null) {
|
|
88
|
+
this.ops.push(Json1.replaceOp(path, prevValue, value));
|
|
89
|
+
}
|
|
90
|
+
else if (!Struct_1.Struct.equals(prevValue, value)) {
|
|
91
|
+
const textEditOps = TextEditOps_1.TextEditOps.between(prevValue, value);
|
|
92
|
+
this.ops.push(Json1.editOp(path, UnicodeText.type, textEditOps));
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
this.ops.push(Json1.insertOp(path, value));
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
setPathValue(path, value) {
|
|
100
|
+
const prevValue = JsonPathSelect.getValueAtPath(this.model.doc, path);
|
|
101
|
+
if (prevValue !== undefined) {
|
|
102
|
+
if (!Struct_1.Struct.equals(prevValue, value)) {
|
|
103
|
+
this.ops.push(Json1.replaceOp(path, prevValue, value));
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
this.ops.push(Json1.insertOp(path, value));
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
move(originPath, destinationPath) {
|
|
111
|
+
this.ops.push(Json1.moveOp(originPath, destinationPath));
|
|
112
|
+
}
|
|
113
|
+
insertIntoArray(arrayPath, index, value) {
|
|
114
|
+
let array = JsonPathSelect.getValueAtPath(this.model.doc, arrayPath);
|
|
115
|
+
if (array === undefined) {
|
|
116
|
+
this.ops.push(Json1.insertOp(arrayPath, [value]));
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
if (!Array.isArray(array)) {
|
|
120
|
+
throw new Error(`path '${JSON.stringify(arrayPath)}' does not refer to an array: ${JSON.stringify(this.model.doc.data)}`);
|
|
121
|
+
}
|
|
122
|
+
const path = Struct_1.Struct.clone(arrayPath);
|
|
123
|
+
path.push(index);
|
|
124
|
+
this.ops.push(Json1.insertOp(path, value));
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
unshiftIntoArray(path, value) {
|
|
128
|
+
path = Struct_1.Struct.clone(path);
|
|
129
|
+
let array = JsonPathSelect.getValueAtPath(this.model.doc, path);
|
|
130
|
+
if (array === undefined) {
|
|
131
|
+
this.ops.push(Json1.insertOp(path, [value]));
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
if (!Array.isArray(array)) {
|
|
135
|
+
throw new Error(`path '${JSON.stringify(path)}' does not refer to an array: ${JSON.stringify(this.model.doc.data)}`);
|
|
136
|
+
}
|
|
137
|
+
path.push(0);
|
|
138
|
+
this.ops.push(Json1.insertOp(path, value));
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
pushIntoArray(path, value) {
|
|
142
|
+
path = Struct_1.Struct.clone(path);
|
|
143
|
+
let array = JsonPathSelect.getValueAtPath(this.model.doc, path);
|
|
144
|
+
if (array === undefined) {
|
|
145
|
+
this.ops.push(Json1.insertOp(path, [value]));
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
if (!Array.isArray(array)) {
|
|
149
|
+
throw new Error(`path '${JSON.stringify(path)}' does not refer to an array: ${JSON.stringify(this.model.doc.data)}`);
|
|
150
|
+
}
|
|
151
|
+
path.push(array.length);
|
|
152
|
+
this.ops.push(Json1.insertOp(path, value));
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
removeValueAtPath(path) {
|
|
156
|
+
let prevValue = JsonPathSelect.getValueAtPath(this.model.doc, path);
|
|
157
|
+
if (prevValue !== undefined) {
|
|
158
|
+
this.ops.push(Json1.removeOp(path, prevValue));
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
replaceValueAtPath(path, value) {
|
|
162
|
+
let prevValue = JsonPathSelect.getValueAtPath(this.model.doc, path);
|
|
163
|
+
if (prevValue !== undefined) {
|
|
164
|
+
this.ops.push(Json1.replaceOp(path, prevValue, value));
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
this.ops.push(Json1.insertOp(path, value));
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
applyRichText(path, deltaOps) {
|
|
171
|
+
this.ops.push(Json1.editOp(path, RichText.type, deltaOps));
|
|
172
|
+
}
|
|
173
|
+
commit() {
|
|
174
|
+
const batch = this;
|
|
175
|
+
if (batch.ops.length > 0) {
|
|
176
|
+
// Update the timestamp of the model (omitting local-time for Manifest objects (which are not Content)).
|
|
177
|
+
this.setPathValue(['meta', 'updated_at', 'utc_time'], batch.time.utc_time);
|
|
178
|
+
if (batch.model instanceof Content_1.Content) {
|
|
179
|
+
this.setPathValue(['meta', 'updated_at', 'local_time'], batch.time.local_time);
|
|
180
|
+
}
|
|
181
|
+
const reduced = batch.ops.reduce(Json1.type.compose, null);
|
|
182
|
+
const shareSync = ShareSync_1.ShareSyncFactory.get();
|
|
183
|
+
batch.model.doc.submitOp(reduced, (error) => {
|
|
184
|
+
if (error) {
|
|
185
|
+
shareSync.onOperationError(error);
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
if (batch.model instanceof Content_1.Content) {
|
|
189
|
+
batch.model.modelUpdated();
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
exports.BatchOperation = BatchOperation;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export type TextEditRetainOp = number;
|
|
2
|
+
export type TextEditInsertOp = string;
|
|
3
|
+
export interface TextEditDeleteOp {
|
|
4
|
+
d: number | String;
|
|
5
|
+
}
|
|
6
|
+
export type TextEditOp = TextEditRetainOp | TextEditInsertOp | TextEditDeleteOp;
|
|
7
|
+
export declare class TextEditOps {
|
|
8
|
+
static between(before: string, after: string): TextEditOp[];
|
|
9
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TextEditOps = void 0;
|
|
4
|
+
const fast_array_diff_1 = require("fast-array-diff");
|
|
5
|
+
;
|
|
6
|
+
class TextEditOps {
|
|
7
|
+
static between(before, after) {
|
|
8
|
+
let ops = [];
|
|
9
|
+
if (before.length === 0 && after.length === 0) {
|
|
10
|
+
return ops;
|
|
11
|
+
}
|
|
12
|
+
else if (before.length === 0) {
|
|
13
|
+
ops.push(after);
|
|
14
|
+
}
|
|
15
|
+
else if (after.length === 0) {
|
|
16
|
+
ops.push({ d: before });
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
// First, we split the string into unicode characters. We use this method of splitting (regex with 'u' flag)
|
|
20
|
+
// in order to split on actual unicode characters, rather than merely on bytes. Even the String.charAt()
|
|
21
|
+
// function can't be trusted to handle multi-byte characters correctly (e.g., emojis). For more info, read here:
|
|
22
|
+
// https://stackoverflow.com/questions/35223206/how-to-split-unicode-string-to-characters-in-javascript
|
|
23
|
+
const beforeChars = before.match(/./ug);
|
|
24
|
+
const afterChars = after.match(/./ug);
|
|
25
|
+
// Create a diff-patch between these two character arrays.
|
|
26
|
+
let patch = (0, fast_array_diff_1.getPatch)(beforeChars, afterChars);
|
|
27
|
+
// console.log(JSON.stringify(patch));
|
|
28
|
+
let cursor = 0;
|
|
29
|
+
// Iterate through the patch items, and use them to construct OT operations, in the format expected by ShareDB.
|
|
30
|
+
for (let i = 0; i < patch.length; i++) {
|
|
31
|
+
const item = patch[i];
|
|
32
|
+
const chunk = item.items.join('');
|
|
33
|
+
if (item.oldPos > cursor) {
|
|
34
|
+
const charsToRetain = item.oldPos - cursor;
|
|
35
|
+
ops.push(charsToRetain);
|
|
36
|
+
cursor += charsToRetain;
|
|
37
|
+
}
|
|
38
|
+
if (item.type == 'add') {
|
|
39
|
+
ops.push(chunk);
|
|
40
|
+
}
|
|
41
|
+
else if (item.type == 'remove') {
|
|
42
|
+
ops.push({ d: chunk });
|
|
43
|
+
cursor += chunk.length;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return ops;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
exports.TextEditOps = TextEditOps;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// created from 'create-ts-index'
|
|
3
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k;
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
+
}
|
|
9
|
+
Object.defineProperty(o, k2, desc);
|
|
10
|
+
}) : (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k;
|
|
12
|
+
o[k2] = m[k];
|
|
13
|
+
}));
|
|
14
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
15
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
16
|
+
};
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
__exportStar(require("./BodyFormat"), exports);
|
|
19
|
+
__exportStar(require("./ChangeModel"), exports);
|
|
20
|
+
__exportStar(require("./DeltaOps"), exports);
|
|
21
|
+
__exportStar(require("./HtmlMarkup"), exports);
|
|
22
|
+
__exportStar(require("./Operation"), exports);
|
|
23
|
+
__exportStar(require("./TextEditOps"), exports);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare abstract class ConnectionListener {
|
|
2
|
+
private _onSocketEvent;
|
|
3
|
+
constructor(onSocketEvent: (eventName: string, details: any) => void);
|
|
4
|
+
onSocketEvent(eventName: string, details: any): void;
|
|
5
|
+
}
|
|
6
|
+
export declare class NoOpConnectionListener extends ConnectionListener {
|
|
7
|
+
constructor();
|
|
8
|
+
static onSocketEvent(eventName: string, details: any): void;
|
|
9
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NoOpConnectionListener = exports.ConnectionListener = void 0;
|
|
4
|
+
class ConnectionListener {
|
|
5
|
+
constructor(onSocketEvent) {
|
|
6
|
+
this._onSocketEvent = onSocketEvent;
|
|
7
|
+
}
|
|
8
|
+
onSocketEvent(eventName, details) {
|
|
9
|
+
this._onSocketEvent(eventName, details);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
exports.ConnectionListener = ConnectionListener;
|
|
13
|
+
class NoOpConnectionListener extends ConnectionListener {
|
|
14
|
+
constructor() {
|
|
15
|
+
super(NoOpConnectionListener.onSocketEvent);
|
|
16
|
+
}
|
|
17
|
+
static onSocketEvent(eventName, details) {
|
|
18
|
+
// DO NOTHING
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.NoOpConnectionListener = NoOpConnectionListener;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import * as Json1 from 'ot-json1';
|
|
2
|
+
export * from 'ot-json1';
|
|
3
|
+
export declare const type: {
|
|
4
|
+
transform(op1: Json1.JSONOpList, op2: Json1.JSONOpList, side: "left" | "right"): Json1.JSONOpList;
|
|
5
|
+
name: string;
|
|
6
|
+
uri: string;
|
|
7
|
+
readCursor: (op: Json1.JSONOpList) => Json1.ReadCursor;
|
|
8
|
+
writeCursor: () => Json1.WriteCursor;
|
|
9
|
+
create(data: Json1.Doc): Json1.Doc;
|
|
10
|
+
isNoop(op: Json1.JSONOpList): boolean;
|
|
11
|
+
setDebug(val: boolean): void;
|
|
12
|
+
registerSubtype: (subtype: {
|
|
13
|
+
[k: string]: any;
|
|
14
|
+
name: string;
|
|
15
|
+
uri?: string;
|
|
16
|
+
apply(doc: any, op: any): any;
|
|
17
|
+
compose(op1: any, op2: any): any;
|
|
18
|
+
transform(op1: any, op2: any, by: "left" | "right"): any;
|
|
19
|
+
isNoop?: (op: any) => boolean;
|
|
20
|
+
invert?: (op: any) => any;
|
|
21
|
+
makeInvertible?: (op: any, doc: any) => any;
|
|
22
|
+
} | {
|
|
23
|
+
[k: string]: any;
|
|
24
|
+
type: {
|
|
25
|
+
[k: string]: any;
|
|
26
|
+
name: string;
|
|
27
|
+
uri?: string;
|
|
28
|
+
apply(doc: any, op: any): any;
|
|
29
|
+
compose(op1: any, op2: any): any;
|
|
30
|
+
transform(op1: any, op2: any, by: "left" | "right"): any;
|
|
31
|
+
isNoop?: (op: any) => boolean;
|
|
32
|
+
invert?: (op: any) => any;
|
|
33
|
+
makeInvertible?: (op: any, doc: any) => any;
|
|
34
|
+
};
|
|
35
|
+
}) => void;
|
|
36
|
+
checkValidOp: (op: Json1.JSONOpList) => void;
|
|
37
|
+
normalize: (op: Json1.JSONOpList) => Json1.JSONOpList;
|
|
38
|
+
apply: (snapshot: Json1.Doc, op: Json1.JSONOpList) => string | number | boolean | {
|
|
39
|
+
[k: string]: Json1.Doc;
|
|
40
|
+
} | Json1.Doc[];
|
|
41
|
+
transformPosition: (path: Json1.Path, op: Json1.JSONOpList) => Json1.Path;
|
|
42
|
+
compose: (op1: Json1.JSONOpList, op2: Json1.JSONOpList) => Json1.JSONOpList;
|
|
43
|
+
tryTransform: (op1: Json1.JSONOpList, op2: Json1.JSONOpList, direction: "left" | "right") => {
|
|
44
|
+
ok: true;
|
|
45
|
+
result: Json1.JSONOpList;
|
|
46
|
+
} | {
|
|
47
|
+
ok: false;
|
|
48
|
+
conflict: Json1.Conflict;
|
|
49
|
+
};
|
|
50
|
+
makeInvertible: (op: Json1.JSONOpList, doc: Json1.Doc) => Json1.JSONOpList;
|
|
51
|
+
invert: (op: Json1.JSONOpList) => Json1.JSONOpList;
|
|
52
|
+
invertWithDoc: (op: Json1.JSONOpList, doc: Json1.Doc) => Json1.JSONOpList;
|
|
53
|
+
RM_UNEXPECTED_CONTENT: Json1.ConflictType;
|
|
54
|
+
DROP_COLLISION: Json1.ConflictType;
|
|
55
|
+
BLACKHOLE: Json1.ConflictType;
|
|
56
|
+
transformNoConflict: (op1: Json1.JSONOpList, op2: Json1.JSONOpList, side: "left" | "right") => Json1.JSONOpList;
|
|
57
|
+
typeAllowingConflictsPred: any;
|
|
58
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
26
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.type = void 0;
|
|
30
|
+
const Json1 = __importStar(require("ot-json1"));
|
|
31
|
+
__exportStar(require("ot-json1"), exports);
|
|
32
|
+
// Export a version of ot-json1 that allows various conflicts
|
|
33
|
+
exports.type = {
|
|
34
|
+
...Json1.type.typeAllowingConflictsPred((conflict) => {
|
|
35
|
+
return (Json1.type.DROP_COLLISION === conflict.type
|
|
36
|
+
|| Json1.type.BLACKHOLE === conflict.type
|
|
37
|
+
|| Json1.type.RM_UNEXPECTED_CONTENT === conflict.type);
|
|
38
|
+
})
|
|
39
|
+
};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { Content, ContentBody, ContentId, ContentRef } from '../models/content/Content';
|
|
2
|
+
import { ContentKind } from "../models/content/ContentKind";
|
|
3
|
+
import { Manifest, ManifestBody } from '../models/content/Manifest';
|
|
4
|
+
import { Model } from '../models/content/Model';
|
|
5
|
+
import { CompactDateTime } from '../models/content/Time';
|
|
6
|
+
import { ConnectionListener } from './ConnectionListener';
|
|
7
|
+
import { Encryption } from '../util/Encryption';
|
|
8
|
+
export declare enum ShareSyncDisposalStrategy {
|
|
9
|
+
UNSUBSCRIBE = 0,
|
|
10
|
+
DESTROY = 1,
|
|
11
|
+
NOTHING = 2
|
|
12
|
+
}
|
|
13
|
+
export interface ShareSyncOptions {
|
|
14
|
+
namespace: string;
|
|
15
|
+
debug: boolean;
|
|
16
|
+
disposalStrategy: ShareSyncDisposalStrategy;
|
|
17
|
+
connectionListener: ConnectionListener;
|
|
18
|
+
urlProvider: () => Promise<string>;
|
|
19
|
+
opErrorCallback: (error?: any) => void;
|
|
20
|
+
onReadyCallback?: () => void;
|
|
21
|
+
pingInterval?: number;
|
|
22
|
+
encryptionKey?: string;
|
|
23
|
+
webSocketConstructor?: any;
|
|
24
|
+
}
|
|
25
|
+
export declare class ShareSyncFactory {
|
|
26
|
+
private static INSTANCE;
|
|
27
|
+
static initialize(encryption: Encryption, options: ShareSyncOptions): void;
|
|
28
|
+
static get(): ShareSync;
|
|
29
|
+
}
|
|
30
|
+
export declare class ShareSync {
|
|
31
|
+
private _debug;
|
|
32
|
+
private _disposalStrategy;
|
|
33
|
+
private _opErrorCallback;
|
|
34
|
+
private _modelCache;
|
|
35
|
+
private _encryption;
|
|
36
|
+
private _hasDurableStore;
|
|
37
|
+
private _useDurableStoreEncryption;
|
|
38
|
+
private _durableStoreEncryptionKey;
|
|
39
|
+
private _socketIsOpen;
|
|
40
|
+
private _socket;
|
|
41
|
+
private _connection;
|
|
42
|
+
private _listener;
|
|
43
|
+
constructor(encryption: Encryption, options: ShareSyncOptions);
|
|
44
|
+
isDebug(): boolean;
|
|
45
|
+
isOnline(): boolean;
|
|
46
|
+
ping(): void;
|
|
47
|
+
makeContentId(): ContentId;
|
|
48
|
+
exists(userId: ContentId, kind: ContentKind, ref: ContentRef): Promise<boolean>;
|
|
49
|
+
createManifest(body: ManifestBody): Manifest;
|
|
50
|
+
createContent(body: ContentBody): Content;
|
|
51
|
+
acquire(kind: ContentKind, id: ContentId, timestamp?: CompactDateTime): Promise<Model>;
|
|
52
|
+
load(kind: ContentKind, id: ContentId): Model;
|
|
53
|
+
findAndAcquire(kind: ContentKind, query: any): Promise<Content[]>;
|
|
54
|
+
updateManifestForContent(content: Content): Promise<void>;
|
|
55
|
+
forEachOfflinePendingModel(callback: (kind: ContentKind, id: ContentId) => void): void;
|
|
56
|
+
isDocInInventory(kind: ContentKind, ref: ContentRef, minVersion?: CompactDateTime): boolean;
|
|
57
|
+
dispose(model: Model): void;
|
|
58
|
+
onOperationError(opError: any): void;
|
|
59
|
+
private wrap;
|
|
60
|
+
}
|