@kokimoki/app 1.9.0 → 1.10.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/dist/index.d.ts +0 -2
- package/dist/index.js +1 -2
- package/dist/kokimoki-awareness.d.ts +12 -10
- package/dist/kokimoki-awareness.js +21 -19
- package/dist/kokimoki-client.d.ts +10 -14
- package/dist/kokimoki-client.js +39 -20
- package/dist/kokimoki-local-store.d.ts +3 -3
- package/dist/kokimoki-queue.d.ts +0 -31
- package/dist/kokimoki-queue.js +38 -27
- package/dist/kokimoki-req-res.d.ts +0 -20
- package/dist/kokimoki-req-res.js +198 -143
- package/dist/kokimoki-store.d.ts +8 -8
- package/dist/kokimoki-store.js +5 -5
- package/dist/kokimoki-transaction.d.ts +8 -17
- package/dist/kokimoki-transaction.js +106 -68
- package/dist/kokimoki.min.d.ts +33 -187
- package/dist/kokimoki.min.js +4608 -476
- package/dist/kokimoki.min.js.map +1 -1
- package/dist/room-subscription.js +3 -3
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +3 -2
package/dist/kokimoki.min.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import TypedEmitter from 'typed-emitter';
|
|
2
2
|
import * as Y from 'yjs';
|
|
3
|
+
import { ZodType } from 'zod';
|
|
3
4
|
|
|
4
5
|
interface Paginated<T> {
|
|
5
6
|
items: T[];
|
|
@@ -24,216 +25,61 @@ interface Upload {
|
|
|
24
25
|
tags: string[];
|
|
25
26
|
}
|
|
26
27
|
|
|
27
|
-
declare namespace KokimokiSchema {
|
|
28
|
-
abstract class Generic<T> {
|
|
29
|
-
abstract get defaultValue(): T;
|
|
30
|
-
abstract set defaultValue(value: T);
|
|
31
|
-
}
|
|
32
|
-
class Number extends Generic<number> {
|
|
33
|
-
defaultValue: number;
|
|
34
|
-
constructor(defaultValue?: number);
|
|
35
|
-
}
|
|
36
|
-
function number(defaultValue?: number): Number;
|
|
37
|
-
class String extends Generic<string> {
|
|
38
|
-
defaultValue: string;
|
|
39
|
-
constructor(defaultValue?: string);
|
|
40
|
-
}
|
|
41
|
-
function string(defaultValue?: string): String;
|
|
42
|
-
class Boolean extends Generic<boolean> {
|
|
43
|
-
defaultValue: boolean;
|
|
44
|
-
constructor(defaultValue?: boolean);
|
|
45
|
-
}
|
|
46
|
-
function boolean(defaultValue?: boolean): Boolean;
|
|
47
|
-
class Struct<Data extends Record<string, Generic<unknown>>> extends Generic<{
|
|
48
|
-
[key in keyof Data]: Data[key]["defaultValue"];
|
|
49
|
-
}> {
|
|
50
|
-
fields: Data;
|
|
51
|
-
constructor(fields: Data);
|
|
52
|
-
get defaultValue(): {
|
|
53
|
-
[key in keyof Data]: Data[key]["defaultValue"];
|
|
54
|
-
};
|
|
55
|
-
set defaultValue(value: {
|
|
56
|
-
[key in keyof Data]: Data[key]["defaultValue"];
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
function struct<Data extends Record<string, Generic<unknown>>>(schema: Data): Struct<Data>;
|
|
60
|
-
class Dict<T extends Generic<unknown>> {
|
|
61
|
-
schema: T;
|
|
62
|
-
defaultValue: {
|
|
63
|
-
[key: string]: T["defaultValue"];
|
|
64
|
-
};
|
|
65
|
-
constructor(schema: T, defaultValue?: {
|
|
66
|
-
[key: string]: T["defaultValue"];
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
function dict<T extends Generic<unknown>>(schema: T, defaultValue?: {
|
|
70
|
-
[key: string]: T["defaultValue"];
|
|
71
|
-
}): Dict<T>;
|
|
72
|
-
class List<T extends Generic<unknown>> extends Generic<T["defaultValue"][]> {
|
|
73
|
-
schema: T;
|
|
74
|
-
defaultValue: T["defaultValue"][];
|
|
75
|
-
constructor(schema: T, defaultValue?: T["defaultValue"][]);
|
|
76
|
-
}
|
|
77
|
-
function list<T extends Generic<unknown>>(schema: T, defaultValue?: T["defaultValue"][]): List<T>;
|
|
78
|
-
/**
|
|
79
|
-
* Nullable
|
|
80
|
-
*/
|
|
81
|
-
class Nullable<T extends Generic<unknown>> extends Generic<T["defaultValue"] | null> {
|
|
82
|
-
schema: T;
|
|
83
|
-
defaultValue: T["defaultValue"] | null;
|
|
84
|
-
constructor(schema: T, defaultValue: T["defaultValue"] | null);
|
|
85
|
-
}
|
|
86
|
-
function nullable<T extends Generic<unknown>>(schema: T, defaultValue?: T["defaultValue"] | null): Nullable<T>;
|
|
87
|
-
class StringEnum<T extends readonly string[]> extends Generic<string> {
|
|
88
|
-
readonly options: T;
|
|
89
|
-
defaultValue: T[number];
|
|
90
|
-
constructor(options: T, defaultValue: T[number]);
|
|
91
|
-
}
|
|
92
|
-
function stringEnum<T extends readonly string[]>(options: T, defaultValue: T[number]): StringEnum<T>;
|
|
93
|
-
class StringConst<T extends string> extends Generic<string> {
|
|
94
|
-
readonly defaultValue: T;
|
|
95
|
-
constructor(defaultValue: T);
|
|
96
|
-
}
|
|
97
|
-
function stringConst<T extends string>(defaultValue: T): StringConst<T>;
|
|
98
|
-
class AnyOf<T extends readonly Generic<unknown>[]> extends Generic<T[number]["defaultValue"]> {
|
|
99
|
-
readonly schemas: T;
|
|
100
|
-
defaultValue: T[number]["defaultValue"];
|
|
101
|
-
constructor(schemas: T, defaultValue: T[number]["defaultValue"]);
|
|
102
|
-
}
|
|
103
|
-
function anyOf<T extends readonly Generic<unknown>[]>(schemas: T, defaultValue: T[number]["defaultValue"]): AnyOf<T>;
|
|
104
|
-
class Optional<T extends Generic<unknown>> extends Generic<T["defaultValue"] | undefined> {
|
|
105
|
-
schema: T;
|
|
106
|
-
defaultValue: T["defaultValue"] | undefined;
|
|
107
|
-
constructor(schema: T, defaultValue?: T["defaultValue"] | undefined);
|
|
108
|
-
}
|
|
109
|
-
function optional<T extends Generic<unknown>>(schema: T, defaultValue?: T["defaultValue"] | undefined): Optional<T>;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
28
|
declare enum RoomSubscriptionMode {
|
|
113
29
|
Read = "r",
|
|
114
30
|
Write = "w",
|
|
115
31
|
ReadWrite = "b"
|
|
116
32
|
}
|
|
117
33
|
|
|
118
|
-
declare class KokimokiStore<T
|
|
34
|
+
declare class KokimokiStore<T> {
|
|
119
35
|
readonly roomName: string;
|
|
120
36
|
readonly mode: RoomSubscriptionMode;
|
|
121
37
|
readonly doc: Y.Doc;
|
|
122
|
-
readonly proxy: T
|
|
123
|
-
readonly root: T
|
|
124
|
-
readonly defaultValue: T
|
|
38
|
+
readonly proxy: T;
|
|
39
|
+
readonly root: T;
|
|
40
|
+
readonly defaultValue: T;
|
|
125
41
|
readonly docRoot: Y.Map<unknown>;
|
|
126
|
-
constructor(roomName: string, schema: T
|
|
127
|
-
get(): T
|
|
128
|
-
subscribe(set: (value:
|
|
42
|
+
constructor(roomName: string, schema: ZodType<T>, mode?: RoomSubscriptionMode);
|
|
43
|
+
get(): T;
|
|
44
|
+
subscribe(set: (value: T) => void): () => void;
|
|
129
45
|
onJoin(client: KokimokiClient): Promise<void>;
|
|
130
46
|
onBeforeLeave(client: KokimokiClient): Promise<void>;
|
|
131
47
|
onLeave(client: KokimokiClient): Promise<void>;
|
|
132
48
|
}
|
|
133
49
|
|
|
134
|
-
declare class
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
}[E]) => TypedEventEmitter<{
|
|
143
|
-
messages: (messages: {
|
|
144
|
-
id: string;
|
|
145
|
-
payload: Req["defaultValue"];
|
|
146
|
-
}[]) => void;
|
|
147
|
-
}>;
|
|
148
|
-
readonly off: <E extends "messages">(event: E, listener: {
|
|
149
|
-
messages: (messages: {
|
|
150
|
-
id: string;
|
|
151
|
-
payload: Req["defaultValue"];
|
|
152
|
-
}[]) => void;
|
|
153
|
-
}[E]) => TypedEventEmitter<{
|
|
154
|
-
messages: (messages: {
|
|
155
|
-
id: string;
|
|
156
|
-
payload: Req["defaultValue"];
|
|
157
|
-
}[]) => void;
|
|
158
|
-
}>;
|
|
159
|
-
constructor(roomName: string, payloadSchema: Req, mode: RoomSubscriptionMode);
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
declare class KokimokiTransaction {
|
|
163
|
-
private kmClient;
|
|
164
|
-
private _clones;
|
|
165
|
-
private _updates;
|
|
166
|
-
private _consumeMessagesInRooms;
|
|
167
|
-
private _queueMessageCounter;
|
|
168
|
-
constructor(kmClient: KokimokiClient<any>);
|
|
169
|
-
private _parseTarget;
|
|
170
|
-
private _parsePath;
|
|
171
|
-
private _getClone;
|
|
172
|
-
get<T>(target: T): T;
|
|
173
|
-
set<T>(target: T, value: T): void;
|
|
174
|
-
delete<T>(target: T): void;
|
|
175
|
-
push<T>(target: T[], value: T): void;
|
|
176
|
-
queueMessage<T>(queue: KokimokiQueue<KokimokiSchema.Generic<T>>, payload: T): string;
|
|
177
|
-
consumeMessage<T>(queue: KokimokiQueue<KokimokiSchema.Generic<T>>, messageId: string): void;
|
|
178
|
-
getUpdates(): Promise<{
|
|
179
|
-
updates: {
|
|
180
|
-
roomName: string;
|
|
181
|
-
update: Uint8Array;
|
|
182
|
-
}[];
|
|
183
|
-
consumedMessages: Set<string>;
|
|
184
|
-
}>;
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
declare class KokimokiAwareness<Data extends KokimokiSchema.Generic<unknown>> extends KokimokiStore<KokimokiSchema.Dict<KokimokiSchema.Struct<{
|
|
188
|
-
clientId: KokimokiSchema.String;
|
|
189
|
-
lastPing: KokimokiSchema.Number;
|
|
190
|
-
data: Data;
|
|
191
|
-
}>>> {
|
|
192
|
-
readonly dataSchema: Data;
|
|
50
|
+
declare class KokimokiAwareness<DataT> extends KokimokiStore<{
|
|
51
|
+
[connectionId: string]: {
|
|
52
|
+
clientId: string;
|
|
53
|
+
lastPing: number;
|
|
54
|
+
data: DataT;
|
|
55
|
+
};
|
|
56
|
+
}> {
|
|
57
|
+
readonly dataSchema: ZodType<DataT>;
|
|
193
58
|
private _data;
|
|
194
59
|
private _pingInterval;
|
|
195
60
|
private _kmClients;
|
|
196
|
-
constructor(roomName: string, dataSchema:
|
|
61
|
+
constructor(roomName: string, dataSchema: ZodType<DataT>, _data: DataT, mode?: RoomSubscriptionMode, pingTimeout?: number);
|
|
197
62
|
onJoin(client: KokimokiClient<any>): Promise<void>;
|
|
198
63
|
onBeforeLeave(client: KokimokiClient<any>): Promise<void>;
|
|
199
64
|
onLeave(client: KokimokiClient<any>): Promise<void>;
|
|
200
65
|
getClients(): {
|
|
201
|
-
[clientId: string]:
|
|
66
|
+
[clientId: string]: DataT;
|
|
202
67
|
};
|
|
203
|
-
setData(data:
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
declare class KokimokiReqRes<Req extends KokimokiSchema.Generic<unknown>, Res extends KokimokiSchema.Generic<unknown>> {
|
|
207
|
-
private kmClient;
|
|
208
|
-
readonly serviceName: string;
|
|
209
|
-
readonly reqSchema: Req;
|
|
210
|
-
readonly resSchema: Res;
|
|
211
|
-
private handleRequest;
|
|
212
|
-
private _reqQueueSchema;
|
|
213
|
-
private _resQueueSchema;
|
|
214
|
-
private _reqQueues;
|
|
215
|
-
private _resQueues;
|
|
216
|
-
private _reqPromises;
|
|
217
|
-
private _getReqQueue;
|
|
218
|
-
private _getResQueue;
|
|
219
|
-
constructor(kmClient: KokimokiClient, serviceName: string, reqSchema: Req, resSchema: Res, handleRequest: (payload: Req["defaultValue"]) => Promise<Res["defaultValue"]>);
|
|
220
|
-
private handleRequests;
|
|
221
|
-
private handleResponses;
|
|
222
|
-
send(toClientId: string, payload: Req["defaultValue"], timeout?: number): Promise<Res["defaultValue"]>;
|
|
68
|
+
setData(data: DataT): Promise<void>;
|
|
223
69
|
}
|
|
224
70
|
|
|
225
|
-
declare class KokimokiLocalStore<Data extends
|
|
71
|
+
declare class KokimokiLocalStore<Data> extends KokimokiStore<Data> {
|
|
226
72
|
private readonly localRoomName;
|
|
227
73
|
private _stateKey?;
|
|
228
74
|
private get stateKey();
|
|
229
|
-
constructor(localRoomName: string, schema: Data);
|
|
75
|
+
constructor(localRoomName: string, schema: ZodType<Data>);
|
|
230
76
|
getInitialUpdate(appId: string, clientId: string): {
|
|
231
77
|
roomHash: number;
|
|
232
78
|
initialUpdate: Uint8Array | undefined;
|
|
233
79
|
};
|
|
234
80
|
}
|
|
235
81
|
|
|
236
|
-
declare const KokimokiClient_base: new () =>
|
|
82
|
+
declare const KokimokiClient_base: new () => TypedEmitter<KokimokiClientEvents>;
|
|
237
83
|
declare class KokimokiClient<ClientContextT = any> extends KokimokiClient_base {
|
|
238
84
|
readonly host: string;
|
|
239
85
|
readonly appId: string;
|
|
@@ -298,17 +144,17 @@ declare class KokimokiClient<ClientContextT = any> extends KokimokiClient_base {
|
|
|
298
144
|
exposeScriptingContext(context: any): Promise<void>;
|
|
299
145
|
private sendSubscribeReq;
|
|
300
146
|
private sendUnsubscribeReq;
|
|
301
|
-
join<T
|
|
302
|
-
leave<T
|
|
303
|
-
transact<ReturnT = void>(
|
|
147
|
+
join<T>(store: KokimokiStore<T>): Promise<void>;
|
|
148
|
+
leave<T>(store: KokimokiStore<T>): Promise<void>;
|
|
149
|
+
transact<T extends unknown[], ReturnT = void>(stores: {
|
|
150
|
+
[K in keyof T]: KokimokiStore<T[K]>;
|
|
151
|
+
}, handler: (proxies: T) => ReturnT | Promise<ReturnT>): Promise<ReturnT>;
|
|
304
152
|
close(): Promise<void>;
|
|
305
|
-
getRoomHash<T extends
|
|
153
|
+
getRoomHash<T extends ZodType>(store: KokimokiStore<T>): number;
|
|
306
154
|
/** Initializers */
|
|
307
|
-
store<T extends
|
|
308
|
-
localStore<T
|
|
309
|
-
|
|
310
|
-
awareness<T extends KokimokiSchema.Generic<unknown>>(name: string, dataSchema: T, initialData?: T["defaultValue"], autoJoin?: boolean): KokimokiAwareness<T>;
|
|
311
|
-
reqRes<Req extends KokimokiSchema.Generic<unknown>, Res extends KokimokiSchema.Generic<unknown>>(serviceName: string, reqSchema: Req, resSchema: Res, handleRequest: (payload: Req["defaultValue"]) => Promise<Res["defaultValue"]>): KokimokiReqRes<Req, Res>;
|
|
155
|
+
store<T extends ZodType>(name: string, schema: T, autoJoin?: boolean): KokimokiStore<T>;
|
|
156
|
+
localStore<T>(name: string, schema: ZodType<T>): KokimokiLocalStore<T>;
|
|
157
|
+
awareness<T>(name: string, dataSchema: ZodType<T>, initialData?: T, autoJoin?: boolean): KokimokiAwareness<T>;
|
|
312
158
|
/**
|
|
313
159
|
* Add a new entry to a leaderboard
|
|
314
160
|
* @param leaderboardName
|
|
@@ -375,4 +221,4 @@ declare class RoomSubscription {
|
|
|
375
221
|
close(): void;
|
|
376
222
|
}
|
|
377
223
|
|
|
378
|
-
export { KokimokiAwareness, KokimokiClient, type KokimokiClientEvents,
|
|
224
|
+
export { KokimokiAwareness, KokimokiClient, type KokimokiClientEvents, KokimokiStore, type Paginated, RoomSubscription, RoomSubscriptionMode, type Upload };
|