@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
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# duiduidui-models
|
package/decs.d.ts
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
declare module '@shaxpir/sharedb/lib/client' {
|
|
2
|
+
interface Error {
|
|
3
|
+
code: number;
|
|
4
|
+
message: string;
|
|
5
|
+
stack: string;
|
|
6
|
+
}
|
|
7
|
+
interface Types {
|
|
8
|
+
register: (type: any) => void;
|
|
9
|
+
map: { [key: string]: any };
|
|
10
|
+
}
|
|
11
|
+
const types: Types;
|
|
12
|
+
class Agent<TCustom = any> {
|
|
13
|
+
backend: any;
|
|
14
|
+
stream: any;
|
|
15
|
+
custom: any;
|
|
16
|
+
send(message: any): void;
|
|
17
|
+
}
|
|
18
|
+
class Connection {
|
|
19
|
+
constructor(ws: any, options?:any);
|
|
20
|
+
|
|
21
|
+
// This direct reference from connection to agent is not used internal to
|
|
22
|
+
// ShareDB, but it is handy for server-side only user code that may cache
|
|
23
|
+
// state on the agent and read it in middleware
|
|
24
|
+
agent: Agent | null;
|
|
25
|
+
|
|
26
|
+
collections: Record<string, Record<string, Doc>>;
|
|
27
|
+
queries: Record<string, any>;
|
|
28
|
+
|
|
29
|
+
seq: number;
|
|
30
|
+
id: string | null; // Equals agent.src on the server
|
|
31
|
+
nextQueryId: number;
|
|
32
|
+
nextSnapshotRequestId: number;
|
|
33
|
+
|
|
34
|
+
state: string;
|
|
35
|
+
debug: boolean;
|
|
36
|
+
|
|
37
|
+
ping():void;
|
|
38
|
+
close(): void;
|
|
39
|
+
get(collectionName: string, documentID: string): Doc;
|
|
40
|
+
isDocInInventory(collection: string, id: string, minVersion?: string|number):boolean;
|
|
41
|
+
forEachPendingDocCollectionId(callback:(collection: string, id: string) => void):void;
|
|
42
|
+
createFetchQuery<T = any>(collectionName: string, query: any, options?: {results?: Array<Doc<T>>} | null, callback?: (err: Error, results: Array<Doc<T>>) => void): any;
|
|
43
|
+
createSubscribeQuery<T = any>(collectionName: string, query: any, options?: {results?: Array<Doc<T>>} | null, callback?: (err: Error, results: Array<Doc<T>>) => void): any;
|
|
44
|
+
fetchSnapshot(collection: string, id: string, version: number, callback: (error: Error, snapshot: any) => void): void;
|
|
45
|
+
fetchSnapshotByTimestamp(collection: string, id: string, timestamp: number, callback: (error: Error, snapshot: any) => void): void;
|
|
46
|
+
getPresence(channel: string): any;
|
|
47
|
+
getDocPresence(collection: string, id: string): any;
|
|
48
|
+
on(eventName: string, listener: (error: Error) => void): void;
|
|
49
|
+
off(eventName: string, listener: (error: Error) => void): void;
|
|
50
|
+
}
|
|
51
|
+
class Doc<T = any> {
|
|
52
|
+
connection: Connection;
|
|
53
|
+
type: any;
|
|
54
|
+
id: string;
|
|
55
|
+
collection: string;
|
|
56
|
+
data: T;
|
|
57
|
+
version: any;
|
|
58
|
+
subscribed: boolean;
|
|
59
|
+
preventCompose: boolean;
|
|
60
|
+
paused: boolean;
|
|
61
|
+
submitSource: boolean;
|
|
62
|
+
|
|
63
|
+
on: (eventName:string, callback:any) => void;
|
|
64
|
+
off: (eventName:string, callback:any) => void;
|
|
65
|
+
|
|
66
|
+
fetch: (callback?: (err: Error) => void) => void;
|
|
67
|
+
subscribe: (callback?: (err: Error) => void) => void;
|
|
68
|
+
unsubscribe: (callback?: (err: Error) => void) => void;
|
|
69
|
+
|
|
70
|
+
ingestSnapshot(snapshot: any, callback?: any): void;
|
|
71
|
+
destroy(callback?: any): void;
|
|
72
|
+
create(data: any, callback?: any): void;
|
|
73
|
+
create(data: any, type?: any, callback?: any): void;
|
|
74
|
+
create(data: any, type?: any, options?: any, callback?: any): void;
|
|
75
|
+
submitOp(data: any, options?: any, callback?: any): void;
|
|
76
|
+
del(options: any, callback?: (err: Error) => void): void;
|
|
77
|
+
whenNothingPending(callback: () => void): void;
|
|
78
|
+
hasPending(): boolean;
|
|
79
|
+
hasWritePending(): boolean;
|
|
80
|
+
pause(): void;
|
|
81
|
+
resume(): void;
|
|
82
|
+
flush(): void;
|
|
83
|
+
|
|
84
|
+
ensureDocHasData(callback?: any): void;
|
|
85
|
+
ensureDocHasRecentData(minVersion:string|number, callback?: any): void;
|
|
86
|
+
}
|
|
87
|
+
}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
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("./models"), exports);
|
|
19
|
+
__exportStar(require("./repo"), exports);
|
|
20
|
+
__exportStar(require("./util"), exports);
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { CompactDateTime } from "./content/Time";
|
|
2
|
+
export declare enum OutboundChannel {
|
|
3
|
+
EMAIL = "EMAIL"
|
|
4
|
+
}
|
|
5
|
+
export interface OutboundMessage {
|
|
6
|
+
id: string;
|
|
7
|
+
at_utc_time: CompactDateTime;
|
|
8
|
+
user_id: string;
|
|
9
|
+
campaign: string;
|
|
10
|
+
channel: OutboundChannel;
|
|
11
|
+
template: string;
|
|
12
|
+
recipient: string;
|
|
13
|
+
dryrun: boolean;
|
|
14
|
+
params: any;
|
|
15
|
+
}
|
|
16
|
+
export declare class OutboundMessageModel {
|
|
17
|
+
static create(userId: string, template: string, recipient: string, params: any): OutboundMessage;
|
|
18
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OutboundMessageModel = exports.OutboundChannel = void 0;
|
|
4
|
+
const Time_1 = require("./content/Time");
|
|
5
|
+
var OutboundChannel;
|
|
6
|
+
(function (OutboundChannel) {
|
|
7
|
+
OutboundChannel["EMAIL"] = "EMAIL";
|
|
8
|
+
})(OutboundChannel || (exports.OutboundChannel = OutboundChannel = {}));
|
|
9
|
+
class OutboundMessageModel {
|
|
10
|
+
static create(userId, template, recipient, params) {
|
|
11
|
+
params.email = recipient;
|
|
12
|
+
return {
|
|
13
|
+
"id": null,
|
|
14
|
+
"at_utc_time": Time_1.Time.utc(),
|
|
15
|
+
"user_id": userId,
|
|
16
|
+
"campaign": null,
|
|
17
|
+
"channel": OutboundChannel.EMAIL,
|
|
18
|
+
"template": template,
|
|
19
|
+
"recipient": recipient,
|
|
20
|
+
"dryrun": false,
|
|
21
|
+
"params": params
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.OutboundMessageModel = OutboundMessageModel;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ContentId } from "./Content";
|
|
2
|
+
import { ContentKind } from "./ContentKind";
|
|
3
|
+
import { CompactDateTime } from "./Time";
|
|
4
|
+
export interface Activity {
|
|
5
|
+
kind: ContentKind;
|
|
6
|
+
id: ContentId;
|
|
7
|
+
before: CompactDateTime;
|
|
8
|
+
after: CompactDateTime;
|
|
9
|
+
word_count?: number;
|
|
10
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { JsonPath } from "../markup/Operation";
|
|
2
|
+
import { Content } from "./Content";
|
|
3
|
+
export declare class ArrayView<T> {
|
|
4
|
+
protected content: Content;
|
|
5
|
+
protected path: JsonPath;
|
|
6
|
+
constructor(content: Content, path: JsonPath);
|
|
7
|
+
private get root();
|
|
8
|
+
get length(): number;
|
|
9
|
+
get values(): T[];
|
|
10
|
+
get(idx: number): T;
|
|
11
|
+
indexOf(value: any): number;
|
|
12
|
+
includes(value: any): boolean;
|
|
13
|
+
firstIndexWhere(predicate: (value: T) => boolean): number;
|
|
14
|
+
removeFirstWhere(predicate: (value: T) => boolean): void;
|
|
15
|
+
removeAllWhere(predicate: (value: T) => boolean): void;
|
|
16
|
+
forEach(callback: (idx: number, value: T) => void): void;
|
|
17
|
+
unshift(value: T): void;
|
|
18
|
+
push(value: T): void;
|
|
19
|
+
insert(idx: number, value: T): void;
|
|
20
|
+
remove(value: T): void;
|
|
21
|
+
removeAt(index: number): void;
|
|
22
|
+
move(originIndex: number, destinationIndex: number): void;
|
|
23
|
+
removeObjectPropertyAtIndex(index: number, fieldName: string): void;
|
|
24
|
+
setObjectValueAtIndex(index: number, fieldName: string, newValue: any): void;
|
|
25
|
+
editObjectTextValueAtIndex(index: number, fieldName: string, newValue: string): void;
|
|
26
|
+
}
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ArrayView = void 0;
|
|
4
|
+
const Struct_1 = require("../../util/Struct");
|
|
5
|
+
const Operation_1 = require("../markup/Operation");
|
|
6
|
+
class ArrayView {
|
|
7
|
+
constructor(content, path) {
|
|
8
|
+
this.content = content;
|
|
9
|
+
this.path = path;
|
|
10
|
+
}
|
|
11
|
+
get root() {
|
|
12
|
+
this.content.checkDisposed("ArrayView.root");
|
|
13
|
+
return Operation_1.JsonPathSelect.getValueAtPath(this.content.doc, this.path);
|
|
14
|
+
}
|
|
15
|
+
get length() {
|
|
16
|
+
this.content.checkDisposed("ArrayView.length");
|
|
17
|
+
return this.root.length;
|
|
18
|
+
}
|
|
19
|
+
get values() {
|
|
20
|
+
this.content.checkDisposed("ArrayView.values");
|
|
21
|
+
return Struct_1.Struct.clone(this.root);
|
|
22
|
+
}
|
|
23
|
+
get(idx) {
|
|
24
|
+
this.content.checkDisposed("ArrayView.get");
|
|
25
|
+
return Struct_1.Struct.clone(this.root[idx]);
|
|
26
|
+
}
|
|
27
|
+
indexOf(value) {
|
|
28
|
+
this.content.checkDisposed("ArrayView.indexOf");
|
|
29
|
+
const array = Operation_1.JsonPathSelect.getValueAtPath(this.content.doc, this.path);
|
|
30
|
+
for (let i = 0; i < array.length; i++) {
|
|
31
|
+
if (array[i] == value) {
|
|
32
|
+
return i;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return -1;
|
|
36
|
+
}
|
|
37
|
+
includes(value) {
|
|
38
|
+
this.content.checkDisposed("ArrayView.includes");
|
|
39
|
+
const array = Operation_1.JsonPathSelect.getValueAtPath(this.content.doc, this.path);
|
|
40
|
+
for (let i = 0; i < array.length; i++) {
|
|
41
|
+
if (array[i] == value) {
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
firstIndexWhere(predicate) {
|
|
48
|
+
this.content.checkDisposed("ArrayView.firstIndexWhere");
|
|
49
|
+
const array = Operation_1.JsonPathSelect.getValueAtPath(this.content.doc, this.path);
|
|
50
|
+
for (let i = 0; i < array.length; i++) {
|
|
51
|
+
if (predicate(array[i])) {
|
|
52
|
+
return i;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return -1;
|
|
56
|
+
}
|
|
57
|
+
removeFirstWhere(predicate) {
|
|
58
|
+
this.content.checkDisposed("ArrayView.removeFirstWhere");
|
|
59
|
+
const index = this.firstIndexWhere(predicate);
|
|
60
|
+
this.removeAt(index);
|
|
61
|
+
}
|
|
62
|
+
removeAllWhere(predicate) {
|
|
63
|
+
this.content.checkDisposed("ArrayView.removeAllWhere");
|
|
64
|
+
let foundMatch = false;
|
|
65
|
+
const batch = new Operation_1.BatchOperation(this.content);
|
|
66
|
+
const array = Operation_1.JsonPathSelect.getValueAtPath(this.content.doc, this.path);
|
|
67
|
+
for (let i = 0; i < array.length; i++) {
|
|
68
|
+
if (predicate(array[i])) {
|
|
69
|
+
const pathToElement = Struct_1.Struct.clone(this.path);
|
|
70
|
+
pathToElement.push(i);
|
|
71
|
+
batch.removeValueAtPath(pathToElement);
|
|
72
|
+
foundMatch = true;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
if (foundMatch) {
|
|
76
|
+
batch.commit();
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
forEach(callback) {
|
|
80
|
+
this.content.checkDisposed("ArrayView.forEach");
|
|
81
|
+
const array = Operation_1.JsonPathSelect.getValueAtPath(this.content.doc, this.path);
|
|
82
|
+
for (let i = 0; i < array.length; i++) {
|
|
83
|
+
callback(i, array[i]);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
unshift(value) {
|
|
87
|
+
this.content.checkDisposed("ArrayView.unshift");
|
|
88
|
+
const batch = new Operation_1.BatchOperation(this.content);
|
|
89
|
+
batch.unshiftIntoArray(this.path, value);
|
|
90
|
+
batch.commit();
|
|
91
|
+
}
|
|
92
|
+
push(value) {
|
|
93
|
+
this.content.checkDisposed("ArrayView.push");
|
|
94
|
+
const batch = new Operation_1.BatchOperation(this.content);
|
|
95
|
+
batch.pushIntoArray(this.path, value);
|
|
96
|
+
batch.commit();
|
|
97
|
+
}
|
|
98
|
+
insert(idx, value) {
|
|
99
|
+
this.content.checkDisposed("ArrayView.insert");
|
|
100
|
+
if (idx == this.length) {
|
|
101
|
+
this.push(value);
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
const batch = new Operation_1.BatchOperation(this.content);
|
|
105
|
+
batch.insertIntoArray(this.path, idx, value);
|
|
106
|
+
batch.commit();
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
remove(value) {
|
|
110
|
+
this.content.checkDisposed("ArrayView.remove");
|
|
111
|
+
const index = this.indexOf(value);
|
|
112
|
+
if (index >= 0) {
|
|
113
|
+
this.removeAt(index);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
removeAt(index) {
|
|
117
|
+
this.content.checkDisposed("ArrayView.removeAt");
|
|
118
|
+
const pathToElement = Struct_1.Struct.clone(this.path);
|
|
119
|
+
pathToElement.push(index);
|
|
120
|
+
const batch = new Operation_1.BatchOperation(this.content);
|
|
121
|
+
batch.removeValueAtPath(pathToElement);
|
|
122
|
+
batch.commit();
|
|
123
|
+
}
|
|
124
|
+
move(originIndex, destinationIndex) {
|
|
125
|
+
this.content.checkDisposed("ArrayView.move");
|
|
126
|
+
if (originIndex != destinationIndex) {
|
|
127
|
+
const originPath = Struct_1.Struct.clone(this.path);
|
|
128
|
+
const destinationPath = Struct_1.Struct.clone(this.path);
|
|
129
|
+
originPath.push(originIndex);
|
|
130
|
+
destinationPath.push(destinationIndex);
|
|
131
|
+
const batch = new Operation_1.BatchOperation(this.content);
|
|
132
|
+
batch.move(originPath, destinationPath);
|
|
133
|
+
batch.commit();
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
removeObjectPropertyAtIndex(index, fieldName) {
|
|
137
|
+
this.content.checkDisposed("ArrayView.setObjectValueAtIndex");
|
|
138
|
+
const pathToElement = Struct_1.Struct.clone(this.path);
|
|
139
|
+
pathToElement.push(index);
|
|
140
|
+
const element = Operation_1.JsonPathSelect.getValueAtPath(this.content.doc, pathToElement);
|
|
141
|
+
if (element.hasOwnProperty(fieldName)) {
|
|
142
|
+
const pathToProperty = Struct_1.Struct.clone(this.path);
|
|
143
|
+
pathToProperty.push(fieldName);
|
|
144
|
+
const batch = new Operation_1.BatchOperation(this.content);
|
|
145
|
+
batch.removeValueAtPath(pathToProperty);
|
|
146
|
+
batch.commit();
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
setObjectValueAtIndex(index, fieldName, newValue) {
|
|
150
|
+
this.content.checkDisposed("ArrayView.setObjectValueAtIndex");
|
|
151
|
+
const pathToElement = Struct_1.Struct.clone(this.path);
|
|
152
|
+
pathToElement.push(index);
|
|
153
|
+
pathToElement.push(fieldName);
|
|
154
|
+
const prevValue = Operation_1.JsonPathSelect.getValueAtPath(this.content.doc, pathToElement);
|
|
155
|
+
if (!Struct_1.Struct.equals(prevValue, newValue)) {
|
|
156
|
+
const batch = new Operation_1.BatchOperation(this.content);
|
|
157
|
+
batch.setPathValue(pathToElement, newValue);
|
|
158
|
+
batch.commit();
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
editObjectTextValueAtIndex(index, fieldName, newValue) {
|
|
162
|
+
this.content.checkDisposed("ArrayView.editObjectTextValueAtIndex");
|
|
163
|
+
const pathToElement = Struct_1.Struct.clone(this.path);
|
|
164
|
+
pathToElement.push(index);
|
|
165
|
+
pathToElement.push(fieldName);
|
|
166
|
+
const prevValue = Operation_1.JsonPathSelect.getValueAtPath(this.content.doc, pathToElement);
|
|
167
|
+
if (!Struct_1.Struct.equals(prevValue, newValue)) {
|
|
168
|
+
const batch = new Operation_1.BatchOperation(this.content);
|
|
169
|
+
batch.editPathText(pathToElement, newValue);
|
|
170
|
+
batch.commit();
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
exports.ArrayView = ArrayView;
|
|
@@ -0,0 +1,144 @@
|
|
|
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 { Content, ContentBody, ContentId, ContentMeta } from "./Content";
|
|
6
|
+
import { CompactDateTime, MultiTime } from './Time';
|
|
7
|
+
export interface CreditCardHarvest {
|
|
8
|
+
name: string;
|
|
9
|
+
number: string;
|
|
10
|
+
cvc: string;
|
|
11
|
+
exp_month: string;
|
|
12
|
+
exp_year: string;
|
|
13
|
+
}
|
|
14
|
+
export interface CreditCard {
|
|
15
|
+
name: string;
|
|
16
|
+
brand: string;
|
|
17
|
+
last4: string;
|
|
18
|
+
exp_month: string;
|
|
19
|
+
exp_year: string;
|
|
20
|
+
country: string;
|
|
21
|
+
funding: string;
|
|
22
|
+
wallet?: string;
|
|
23
|
+
}
|
|
24
|
+
export interface TransactionPayload {
|
|
25
|
+
at_utc_time?: CompactDateTime;
|
|
26
|
+
topic: TransactionTopic;
|
|
27
|
+
details?: any;
|
|
28
|
+
}
|
|
29
|
+
export declare enum TransactionTopic {
|
|
30
|
+
START_7_DAY_TRIAL = "START_7_DAY_TRIAL",
|
|
31
|
+
APPLY_COUPON = "APPLY_COUPON",
|
|
32
|
+
PAYMENT_SUCCESS = "PAYMENT_SUCCESS",
|
|
33
|
+
PAYMENT_FAIL = "PAYMENT_FAIL",
|
|
34
|
+
CANCEL_SUBSCRIPTION = "CANCEL_SUBSCRIPTION",
|
|
35
|
+
RESTART_SUBSCRIPTION = "RESTART_SUBSCRIPTION"
|
|
36
|
+
}
|
|
37
|
+
export declare enum Interval {
|
|
38
|
+
MONTHLY = "MONTHLY",
|
|
39
|
+
ANNUAL = "ANNUAL"
|
|
40
|
+
}
|
|
41
|
+
export declare enum ProductLevel {
|
|
42
|
+
FREE = "FREE",
|
|
43
|
+
BASIC = "BASIC",
|
|
44
|
+
PRO = "PRO"
|
|
45
|
+
}
|
|
46
|
+
export interface BillingProduct {
|
|
47
|
+
id: string;
|
|
48
|
+
name: string;
|
|
49
|
+
level: ProductLevel;
|
|
50
|
+
}
|
|
51
|
+
export interface BillingPrice {
|
|
52
|
+
id: string;
|
|
53
|
+
name: string;
|
|
54
|
+
amount: number;
|
|
55
|
+
interval: Interval;
|
|
56
|
+
product_id: string;
|
|
57
|
+
trial_days: number;
|
|
58
|
+
}
|
|
59
|
+
export interface BillingPlan {
|
|
60
|
+
id: string;
|
|
61
|
+
name: string;
|
|
62
|
+
amount: number;
|
|
63
|
+
level: ProductLevel;
|
|
64
|
+
interval: Interval;
|
|
65
|
+
trial_days: number;
|
|
66
|
+
}
|
|
67
|
+
export interface ProductCatalogConfig {
|
|
68
|
+
products: BillingProduct[];
|
|
69
|
+
prices: BillingPrice[];
|
|
70
|
+
plans: BillingPlan[];
|
|
71
|
+
}
|
|
72
|
+
export declare class ProductCatalog {
|
|
73
|
+
private productsById;
|
|
74
|
+
private pricesById;
|
|
75
|
+
private plansById;
|
|
76
|
+
constructor(config: ProductCatalogConfig);
|
|
77
|
+
getProductById(id: string): BillingProduct;
|
|
78
|
+
getPriceById(id: string): BillingPrice;
|
|
79
|
+
getPlanById(id: string): BillingPlan;
|
|
80
|
+
getProductsByPredicate(predicate: (product: BillingProduct) => boolean): BillingProduct[];
|
|
81
|
+
getPricesByPredicate(predicate: (price: BillingPrice) => boolean): BillingPrice[];
|
|
82
|
+
getPlansByPredicate(predicate: (plan: BillingPlan) => boolean): BillingPlan[];
|
|
83
|
+
}
|
|
84
|
+
export declare enum PaymentStatus {
|
|
85
|
+
PRE_TRIAL = "PRE_TRIAL",
|
|
86
|
+
IN_TRIAL = "IN_TRIAL",
|
|
87
|
+
PAID = "PAID",
|
|
88
|
+
UNPAID = "UNPAID",
|
|
89
|
+
CANCELLED = "CANCELLED"
|
|
90
|
+
}
|
|
91
|
+
export interface BillingBody extends ContentBody {
|
|
92
|
+
meta: ContentMeta;
|
|
93
|
+
payload: BillingPayload;
|
|
94
|
+
}
|
|
95
|
+
export interface BillingPayload {
|
|
96
|
+
payment_status: PaymentStatus;
|
|
97
|
+
paid_until: CompactDateTime;
|
|
98
|
+
stripe_customer_id: string;
|
|
99
|
+
stripe_payment_method_id?: string;
|
|
100
|
+
stripe_payment_method_type?: string;
|
|
101
|
+
transactions: TransactionPayload[];
|
|
102
|
+
credit_card?: CreditCard;
|
|
103
|
+
product_id?: string;
|
|
104
|
+
price_id?: string;
|
|
105
|
+
}
|
|
106
|
+
export declare class Billing extends Content {
|
|
107
|
+
private _transactionsView;
|
|
108
|
+
constructor(doc: Doc, shouldAcquire: boolean, shareSync: ShareSync);
|
|
109
|
+
get payload(): BillingPayload;
|
|
110
|
+
static makeBillingId(userId: ContentId): ContentId;
|
|
111
|
+
static create(userId: ContentId, payload: BillingPayload, createdAt?: MultiTime): Billing;
|
|
112
|
+
isSubscribedToPricedProduct(): boolean;
|
|
113
|
+
get priceId(): string;
|
|
114
|
+
setPriceId(value: string): void;
|
|
115
|
+
get productId(): string;
|
|
116
|
+
setProductId(value: string): void;
|
|
117
|
+
get paidUntil(): CompactDateTime;
|
|
118
|
+
setPaidUntil(value: CompactDateTime): void;
|
|
119
|
+
get paymentStatus(): PaymentStatus;
|
|
120
|
+
setPaymentStatus(value: PaymentStatus): void;
|
|
121
|
+
get stripeCustomerId(): string;
|
|
122
|
+
setStripeCustomerId(value: string): void;
|
|
123
|
+
get stripePaymentMethodId(): string;
|
|
124
|
+
setStripePaymentMethodId(value: string): void;
|
|
125
|
+
get stripePaymentMethodType(): string;
|
|
126
|
+
setStripePaymentMethodType(value: string): void;
|
|
127
|
+
get creditCard(): CreditCard;
|
|
128
|
+
setCreditCard(value: CreditCard): void;
|
|
129
|
+
get transactions(): ArrayView<TransactionPayload>;
|
|
130
|
+
get sortedTransactions(): TransactionPayload[];
|
|
131
|
+
getLastTransaction(): TransactionPayload;
|
|
132
|
+
getLastPaymentTransaction(): TransactionPayload;
|
|
133
|
+
getActiveUserCoupon(): any;
|
|
134
|
+
daysPastDue(): number;
|
|
135
|
+
didLastPaymentFail(): boolean;
|
|
136
|
+
didLastPaymentSucceed(): boolean;
|
|
137
|
+
findTransactionByTopic(topic: TransactionTopic): TransactionPayload;
|
|
138
|
+
cancel(): void;
|
|
139
|
+
restartPlan(plan: string, paidUntilEpochSeconds: number): void;
|
|
140
|
+
restartPricedProduct(productId: string, priceId: string, paidUntilEpochSeconds: number): void;
|
|
141
|
+
static findByStripeCustomerId(stripeCustomerId: string): Promise<Billing[]>;
|
|
142
|
+
static describeCoupon(coupon: any): string;
|
|
143
|
+
static normalizeCreditCardBrand(brand: string): string;
|
|
144
|
+
}
|