@kokimoki/app 1.0.6 → 1.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/kokimoki.min.d.ts +348 -0
- package/dist/kokimoki.min.js +12425 -0
- package/dist/kokimoki.min.js.map +1 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +11 -2
|
@@ -0,0 +1,348 @@
|
|
|
1
|
+
import TypedEventEmitter from 'typed-emitter';
|
|
2
|
+
import * as Y from 'yjs';
|
|
3
|
+
|
|
4
|
+
interface Paginated<T> {
|
|
5
|
+
items: T[];
|
|
6
|
+
total: number;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
type KokimokiClientEvents = {
|
|
10
|
+
connected: () => void;
|
|
11
|
+
disconnected: () => void;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
interface Upload {
|
|
15
|
+
id: string;
|
|
16
|
+
appId: string;
|
|
17
|
+
clientId: string;
|
|
18
|
+
createdAt: Date;
|
|
19
|
+
name: string;
|
|
20
|
+
url: string;
|
|
21
|
+
size: number;
|
|
22
|
+
mimeType: string;
|
|
23
|
+
completed: boolean;
|
|
24
|
+
tags: string[];
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
interface FieldOptions {
|
|
28
|
+
label?: string;
|
|
29
|
+
}
|
|
30
|
+
declare abstract class Field<T> {
|
|
31
|
+
readonly options: FieldOptions;
|
|
32
|
+
constructor(options: FieldOptions);
|
|
33
|
+
abstract get value(): T;
|
|
34
|
+
abstract get schema(): any;
|
|
35
|
+
}
|
|
36
|
+
declare class BooleanField extends Field<boolean> {
|
|
37
|
+
value: boolean;
|
|
38
|
+
constructor(value: boolean, options?: FieldOptions);
|
|
39
|
+
get schema(): {
|
|
40
|
+
type: string;
|
|
41
|
+
default: boolean;
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
declare class ConstField<T extends string> extends Field<string extends T ? never : T> {
|
|
45
|
+
value: string extends T ? never : T;
|
|
46
|
+
constructor(value: string extends T ? never : T, options?: FieldOptions);
|
|
47
|
+
get schema(): {
|
|
48
|
+
const: string extends T ? never : T;
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
declare class ImageField extends Field<string> {
|
|
52
|
+
value: string;
|
|
53
|
+
constructor(value: string, options?: FieldOptions);
|
|
54
|
+
get schema(): {
|
|
55
|
+
type: string;
|
|
56
|
+
default: string;
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
declare class TextField extends Field<string> {
|
|
60
|
+
value: string;
|
|
61
|
+
constructor(value: string, options?: FieldOptions);
|
|
62
|
+
get schema(): {
|
|
63
|
+
type: string;
|
|
64
|
+
default: string;
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
declare class EnumField<T extends Record<string, string>> extends Field<keyof T> {
|
|
68
|
+
enumValues: T;
|
|
69
|
+
value: keyof T;
|
|
70
|
+
constructor(enumValues: T, value: keyof T, options?: FieldOptions);
|
|
71
|
+
get schema(): {
|
|
72
|
+
enum: string[];
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
declare class IntegerField extends Field<number> {
|
|
76
|
+
value: number;
|
|
77
|
+
constructor(value: number, options?: FieldOptions);
|
|
78
|
+
get schema(): {
|
|
79
|
+
type: string;
|
|
80
|
+
default: number;
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
declare class FloatField extends Field<number> {
|
|
84
|
+
value: number;
|
|
85
|
+
constructor(value: number, options?: FieldOptions);
|
|
86
|
+
get schema(): {
|
|
87
|
+
type: string;
|
|
88
|
+
default: number;
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
declare class FormGroup<T extends Record<string, Field<any>>, O extends Record<string, Field<any>>> extends Field<{
|
|
92
|
+
[key in keyof T]: T[key]["value"];
|
|
93
|
+
} & Partial<{
|
|
94
|
+
[key in keyof O]: O[key]["value"];
|
|
95
|
+
}>> {
|
|
96
|
+
requiredFields: T;
|
|
97
|
+
optionalFields: O;
|
|
98
|
+
constructor(requiredFields: T, optionalFields?: O, options?: FieldOptions);
|
|
99
|
+
get value(): {
|
|
100
|
+
[key in keyof T]: T[key]["value"];
|
|
101
|
+
} & Partial<{
|
|
102
|
+
[key in keyof O]: O[key]["value"];
|
|
103
|
+
}>;
|
|
104
|
+
get schema(): {
|
|
105
|
+
type: string;
|
|
106
|
+
properties: any;
|
|
107
|
+
required: string[];
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
declare class FormArray<T> extends Field<T[]> {
|
|
111
|
+
private factory;
|
|
112
|
+
value: Field<T>["value"][];
|
|
113
|
+
constructor(factory: () => Field<T>, value: Field<T>["value"][], options?: FieldOptions);
|
|
114
|
+
get schema(): {
|
|
115
|
+
type: string;
|
|
116
|
+
items: any;
|
|
117
|
+
default: T[];
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
declare class Form<R extends Record<string, Field<any>>, O extends Record<string, Field<any>>> extends FormGroup<R, O> {
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
declare namespace KokimokiSchema {
|
|
124
|
+
abstract class Generic<T> {
|
|
125
|
+
abstract get defaultValue(): T;
|
|
126
|
+
abstract set defaultValue(value: T);
|
|
127
|
+
}
|
|
128
|
+
class Number extends Generic<number> {
|
|
129
|
+
defaultValue: number;
|
|
130
|
+
constructor(defaultValue?: number);
|
|
131
|
+
}
|
|
132
|
+
function number(defaultValue?: number): Number;
|
|
133
|
+
class String extends Generic<string> {
|
|
134
|
+
defaultValue: string;
|
|
135
|
+
constructor(defaultValue?: string);
|
|
136
|
+
}
|
|
137
|
+
function string(defaultValue?: string): String;
|
|
138
|
+
class Boolean extends Generic<boolean> {
|
|
139
|
+
defaultValue: boolean;
|
|
140
|
+
constructor(defaultValue?: boolean);
|
|
141
|
+
}
|
|
142
|
+
function boolean(defaultValue?: boolean): Boolean;
|
|
143
|
+
class Struct<Data extends Record<string, Generic<unknown>>> extends Generic<{
|
|
144
|
+
[key in keyof Data]: Data[key]["defaultValue"];
|
|
145
|
+
}> {
|
|
146
|
+
fields: Data;
|
|
147
|
+
constructor(fields: Data);
|
|
148
|
+
get defaultValue(): {
|
|
149
|
+
[key in keyof Data]: Data[key]["defaultValue"];
|
|
150
|
+
};
|
|
151
|
+
set defaultValue(value: {
|
|
152
|
+
[key in keyof Data]: Data[key]["defaultValue"];
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
function struct<Data extends Record<string, Generic<unknown>>>(schema: Data): Struct<Data>;
|
|
156
|
+
class Dict<T extends Generic<unknown>> {
|
|
157
|
+
schema: T;
|
|
158
|
+
defaultValue: {
|
|
159
|
+
[key: string]: T["defaultValue"];
|
|
160
|
+
};
|
|
161
|
+
constructor(schema: T, defaultValue?: {
|
|
162
|
+
[key: string]: T["defaultValue"];
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
function dict<T extends Generic<unknown>>(schema: T, defaultValue?: {
|
|
166
|
+
[key: string]: T["defaultValue"];
|
|
167
|
+
}): Dict<T>;
|
|
168
|
+
class List<T extends Generic<unknown>> extends Generic<T["defaultValue"][]> {
|
|
169
|
+
schema: T;
|
|
170
|
+
defaultValue: T["defaultValue"][];
|
|
171
|
+
constructor(schema: T, defaultValue?: T["defaultValue"][]);
|
|
172
|
+
}
|
|
173
|
+
function list<T extends Generic<unknown>>(schema: T, defaultValue?: T["defaultValue"][]): List<T>;
|
|
174
|
+
/**
|
|
175
|
+
* Nullable
|
|
176
|
+
*/
|
|
177
|
+
class Nullable<T extends Generic<unknown>> extends Generic<T["defaultValue"] | null> {
|
|
178
|
+
schema: T;
|
|
179
|
+
defaultValue: T["defaultValue"] | null;
|
|
180
|
+
constructor(schema: T, defaultValue: T["defaultValue"] | null);
|
|
181
|
+
}
|
|
182
|
+
function nullable<T extends Generic<unknown>>(schema: T, defaultValue?: T["defaultValue"] | null): Nullable<T>;
|
|
183
|
+
class StringEnum<T extends readonly string[]> extends Generic<string> {
|
|
184
|
+
readonly options: T;
|
|
185
|
+
defaultValue: T[number];
|
|
186
|
+
constructor(options: T, defaultValue: T[number]);
|
|
187
|
+
}
|
|
188
|
+
function stringEnum<T extends readonly string[]>(options: T, defaultValue: T[number]): StringEnum<T>;
|
|
189
|
+
class StringConst<T extends string> extends Generic<string> {
|
|
190
|
+
readonly defaultValue: T;
|
|
191
|
+
constructor(defaultValue: T);
|
|
192
|
+
}
|
|
193
|
+
function stringConst<T extends string>(defaultValue: T): StringConst<T>;
|
|
194
|
+
class AnyOf<T extends readonly Generic<unknown>[]> extends Generic<T[number]["defaultValue"]> {
|
|
195
|
+
readonly schemas: T;
|
|
196
|
+
defaultValue: T[number]["defaultValue"];
|
|
197
|
+
constructor(schemas: T, defaultValue: T[number]["defaultValue"]);
|
|
198
|
+
}
|
|
199
|
+
function anyOf<T extends readonly Generic<unknown>[]>(schemas: T, defaultValue: T[number]["defaultValue"]): AnyOf<T>;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
declare enum RoomSubscriptionMode {
|
|
203
|
+
Read = "r",
|
|
204
|
+
Write = "w",
|
|
205
|
+
ReadWrite = "b"
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
declare class KokimokiStore<T extends KokimokiSchema.Generic<unknown>> {
|
|
209
|
+
readonly roomName: string;
|
|
210
|
+
readonly mode: RoomSubscriptionMode;
|
|
211
|
+
readonly doc: Y.Doc;
|
|
212
|
+
readonly proxy: T["defaultValue"];
|
|
213
|
+
readonly root: T["defaultValue"];
|
|
214
|
+
readonly defaultValue: T["defaultValue"];
|
|
215
|
+
readonly docRoot: Y.Map<unknown>;
|
|
216
|
+
constructor(roomName: string, schema: T, mode?: RoomSubscriptionMode);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
declare class KokimokiQueue<Req extends KokimokiSchema.Generic<unknown>> extends KokimokiStore<KokimokiSchema.Dict<KokimokiSchema.Struct<{
|
|
220
|
+
timestamp: KokimokiSchema.Number;
|
|
221
|
+
payload: Req;
|
|
222
|
+
}>>> {
|
|
223
|
+
readonly payloadSchema: Req;
|
|
224
|
+
private _emitter;
|
|
225
|
+
readonly on: <E extends "messages">(event: E, listener: {
|
|
226
|
+
messages: (messages: {
|
|
227
|
+
id: string;
|
|
228
|
+
payload: Req["defaultValue"];
|
|
229
|
+
}[]) => void;
|
|
230
|
+
}[E]) => TypedEventEmitter<{
|
|
231
|
+
messages: (messages: {
|
|
232
|
+
id: string;
|
|
233
|
+
payload: Req["defaultValue"];
|
|
234
|
+
}[]) => void;
|
|
235
|
+
}>;
|
|
236
|
+
readonly off: <E extends "messages">(event: E, listener: {
|
|
237
|
+
messages: (messages: {
|
|
238
|
+
id: string;
|
|
239
|
+
payload: Req["defaultValue"];
|
|
240
|
+
}[]) => void;
|
|
241
|
+
}[E]) => TypedEventEmitter<{
|
|
242
|
+
messages: (messages: {
|
|
243
|
+
id: string;
|
|
244
|
+
payload: Req["defaultValue"];
|
|
245
|
+
}[]) => void;
|
|
246
|
+
}>;
|
|
247
|
+
constructor(roomName: string, payloadSchema: Req, mode: RoomSubscriptionMode);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
declare class KokimokiTransaction {
|
|
251
|
+
private kmClient;
|
|
252
|
+
private _clones;
|
|
253
|
+
private _updates;
|
|
254
|
+
private _consumeMessagesInRooms;
|
|
255
|
+
constructor(kmClient: KokimokiClient<any>);
|
|
256
|
+
private _parseTarget;
|
|
257
|
+
private _parsePath;
|
|
258
|
+
private _getClone;
|
|
259
|
+
get<T>(target: T): T;
|
|
260
|
+
set<T>(target: T, value: T): void;
|
|
261
|
+
delete<T>(target: T): void;
|
|
262
|
+
push<T>(target: T[], value: T): void;
|
|
263
|
+
queueMessage<T>(queue: KokimokiQueue<KokimokiSchema.Generic<T>>, payload: T): void;
|
|
264
|
+
consumeMessage<T>(queue: KokimokiQueue<KokimokiSchema.Generic<T>>, messageId: string): void;
|
|
265
|
+
getUpdates(): Promise<{
|
|
266
|
+
updates: {
|
|
267
|
+
roomName: string;
|
|
268
|
+
update: Uint8Array;
|
|
269
|
+
}[];
|
|
270
|
+
consumedMessages: Set<string>;
|
|
271
|
+
}>;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
declare const KokimokiClient_base: new () => TypedEventEmitter<KokimokiClientEvents>;
|
|
275
|
+
declare class KokimokiClient<ClientContextT = any> extends KokimokiClient_base {
|
|
276
|
+
readonly host: string;
|
|
277
|
+
readonly appId: string;
|
|
278
|
+
readonly code: string;
|
|
279
|
+
private _wsUrl;
|
|
280
|
+
private _apiUrl;
|
|
281
|
+
private _id?;
|
|
282
|
+
private _token?;
|
|
283
|
+
private _apiHeaders?;
|
|
284
|
+
private _serverTimeOffset;
|
|
285
|
+
private _clientContext?;
|
|
286
|
+
private _ws?;
|
|
287
|
+
private _subscriptionsByName;
|
|
288
|
+
private _subscriptionsByHash;
|
|
289
|
+
private _subscribeReqPromises;
|
|
290
|
+
private _transactionPromises;
|
|
291
|
+
private _connected;
|
|
292
|
+
private _connectPromise?;
|
|
293
|
+
private _messageId;
|
|
294
|
+
private _reconnectTimeout;
|
|
295
|
+
private _pingInterval;
|
|
296
|
+
constructor(host: string, appId: string, code?: string);
|
|
297
|
+
get id(): string;
|
|
298
|
+
get token(): string;
|
|
299
|
+
get apiUrl(): string;
|
|
300
|
+
get apiHeaders(): Headers;
|
|
301
|
+
get clientContext(): ClientContextT & ({} | null);
|
|
302
|
+
get connected(): boolean;
|
|
303
|
+
get ws(): WebSocket;
|
|
304
|
+
connect(): Promise<void>;
|
|
305
|
+
private handleInitMessage;
|
|
306
|
+
private handleBinaryMessage;
|
|
307
|
+
private handleErrorMessage;
|
|
308
|
+
private handleSubscribeResMessage;
|
|
309
|
+
private handleRoomUpdateMessage;
|
|
310
|
+
serverTimestamp(): number;
|
|
311
|
+
patchRoomState(room: string, update: Uint8Array): Promise<any>;
|
|
312
|
+
private createUpload;
|
|
313
|
+
private uploadChunks;
|
|
314
|
+
private completeUpload;
|
|
315
|
+
upload(name: string, blob: Blob, tags?: string[]): Promise<Upload>;
|
|
316
|
+
updateUpload(id: string, update: {
|
|
317
|
+
tags?: string[];
|
|
318
|
+
}): Promise<Upload>;
|
|
319
|
+
listUploads(filter?: {
|
|
320
|
+
clientId?: string;
|
|
321
|
+
mimeTypes?: string[];
|
|
322
|
+
tags?: string[];
|
|
323
|
+
}, skip?: number, limit?: number): Promise<Paginated<Upload>>;
|
|
324
|
+
deleteUpload(id: string): Promise<{
|
|
325
|
+
acknowledged: boolean;
|
|
326
|
+
deletedCount: number;
|
|
327
|
+
}>;
|
|
328
|
+
exposeScriptingContext(context: any): Promise<void>;
|
|
329
|
+
private sendSubscriptionReq;
|
|
330
|
+
join<T extends KokimokiSchema.Generic<unknown>>(store: KokimokiStore<T>): Promise<void>;
|
|
331
|
+
transact(handler: (t: KokimokiTransaction) => void): Promise<void>;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
declare class RoomSubscription {
|
|
335
|
+
private kmClient;
|
|
336
|
+
readonly store: KokimokiStore<any>;
|
|
337
|
+
private _joined;
|
|
338
|
+
private _roomHash?;
|
|
339
|
+
private _onDisconnect;
|
|
340
|
+
constructor(kmClient: KokimokiClient, store: KokimokiStore<any>);
|
|
341
|
+
get roomName(): string;
|
|
342
|
+
get roomHash(): number;
|
|
343
|
+
get joined(): boolean;
|
|
344
|
+
applyInitialResponse(roomHash: number, initialUpdate?: Uint8Array): Promise<void>;
|
|
345
|
+
close(): void;
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
export { BooleanField, ConstField, EnumField, Field, type FieldOptions, FloatField, Form, FormArray, FormGroup, ImageField, IntegerField, KokimokiClient, type KokimokiClientEvents, KokimokiQueue, KokimokiSchema, KokimokiStore, type Paginated, RoomSubscription, RoomSubscriptionMode, TextField, type Upload };
|