@kokimoki/app 1.10.2 → 1.11.1

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.
@@ -1,7 +1,6 @@
1
1
  import { KokimokiStore } from "./kokimoki-store";
2
2
  import { RoomSubscriptionMode } from "./room-subscription-mode";
3
3
  import type { KokimokiClient } from "./kokimoki-client";
4
- import { ZodType } from "zod";
5
4
  export declare class KokimokiAwareness<DataT> extends KokimokiStore<{
6
5
  [connectionId: string]: {
7
6
  clientId: string;
@@ -9,11 +8,10 @@ export declare class KokimokiAwareness<DataT> extends KokimokiStore<{
9
8
  data: DataT;
10
9
  };
11
10
  }> {
12
- readonly dataSchema: ZodType<DataT>;
13
11
  private _data;
14
12
  private _pingInterval;
15
13
  private _kmClients;
16
- constructor(roomName: string, dataSchema: ZodType<DataT>, _data: DataT, mode?: RoomSubscriptionMode, pingTimeout?: number);
14
+ constructor(roomName: string, _data: DataT, mode?: RoomSubscriptionMode, pingTimeout?: number);
17
15
  onJoin(client: KokimokiClient<any>): Promise<void>;
18
16
  onBeforeLeave(client: KokimokiClient<any>): Promise<void>;
19
17
  onLeave(client: KokimokiClient<any>): Promise<void>;
@@ -1,20 +1,11 @@
1
1
  import { KokimokiStore } from "./kokimoki-store";
2
2
  import { RoomSubscriptionMode } from "./room-subscription-mode";
3
- import { z } from "zod";
4
3
  export class KokimokiAwareness extends KokimokiStore {
5
- dataSchema;
6
4
  _data;
7
5
  _pingInterval = null;
8
6
  _kmClients = new Set();
9
- constructor(roomName, dataSchema, _data, mode = RoomSubscriptionMode.ReadWrite, pingTimeout = 3000) {
10
- super(`/a/${roomName}`,
11
- // @ts-ignore
12
- z.record(z.string(), z.object({
13
- clientId: z.string(),
14
- lastPing: z.number(),
15
- data: dataSchema,
16
- })), {}, mode);
17
- this.dataSchema = dataSchema;
7
+ constructor(roomName, _data, mode = RoomSubscriptionMode.ReadWrite, pingTimeout = 3000) {
8
+ super(`/a/${roomName}`, {}, mode);
18
9
  this._data = _data;
19
10
  this._pingInterval = setInterval(async () => {
20
11
  const kmClients = Array.from(this._kmClients);
@@ -5,7 +5,6 @@ import type { Paginated } from "./types/common";
5
5
  import { KokimokiStore } from "./kokimoki-store";
6
6
  import { KokimokiAwareness } from "./kokimoki-awareness";
7
7
  import { KokimokiLocalStore } from "./kokimoki-local-store";
8
- import { ZodType } from "zod";
9
8
  declare const KokimokiClient_base: new () => TypedEmitter<KokimokiClientEvents>;
10
9
  export declare class KokimokiClient<ClientContextT = any> extends KokimokiClient_base {
11
10
  readonly host: string;
@@ -77,11 +76,11 @@ export declare class KokimokiClient<ClientContextT = any> extends KokimokiClient
77
76
  [K in keyof T]: KokimokiStore<T[K]>;
78
77
  }, handler: (proxies: T) => ReturnT | Promise<ReturnT>): Promise<ReturnT>;
79
78
  close(): Promise<void>;
80
- getRoomHash<T extends ZodType>(store: KokimokiStore<T>): number;
79
+ getRoomHash<T>(store: KokimokiStore<T>): number;
81
80
  /** Initializers */
82
- store<T>(name: string, schema: ZodType<T>, defaultState: T, autoJoin?: boolean): KokimokiStore<T>;
83
- localStore<T>(name: string, schema: ZodType<T>, defaultState: T): KokimokiLocalStore<T>;
84
- awareness<T>(name: string, dataSchema: ZodType<T>, initialData: T, autoJoin?: boolean): KokimokiAwareness<T>;
81
+ store<T>(name: string, defaultState: T, autoJoin?: boolean): KokimokiStore<T>;
82
+ localStore<T>(name: string, defaultState: T): KokimokiLocalStore<T>;
83
+ awareness<T>(name: string, initialData: T, autoJoin?: boolean): KokimokiAwareness<T>;
85
84
  /**
86
85
  * Add a new entry to a leaderboard
87
86
  * @param leaderboardName
@@ -569,8 +569,8 @@ export class KokimokiClient extends EventEmitter {
569
569
  }
570
570
  /** Initializers */
571
571
  // store
572
- store(name, schema, defaultState, autoJoin = true) {
573
- const store = new KokimokiStore(name, schema, defaultState);
572
+ store(name, defaultState, autoJoin = true) {
573
+ const store = new KokimokiStore(name, defaultState);
574
574
  if (autoJoin) {
575
575
  this.join(store)
576
576
  .then(() => { })
@@ -579,8 +579,8 @@ export class KokimokiClient extends EventEmitter {
579
579
  return store;
580
580
  }
581
581
  // local store
582
- localStore(name, schema, defaultState) {
583
- const store = new KokimokiLocalStore(name, schema, defaultState);
582
+ localStore(name, defaultState) {
583
+ const store = new KokimokiLocalStore(name, defaultState);
584
584
  this.join(store)
585
585
  .then(() => { })
586
586
  .catch(() => { });
@@ -602,8 +602,8 @@ export class KokimokiClient extends EventEmitter {
602
602
  // return queue;
603
603
  // }
604
604
  // awareness
605
- awareness(name, dataSchema, initialData, autoJoin = true) {
606
- const awareness = new KokimokiAwareness(name, dataSchema, initialData);
605
+ awareness(name, initialData, autoJoin = true) {
606
+ const awareness = new KokimokiAwareness(name, initialData);
607
607
  if (autoJoin) {
608
608
  this.join(awareness)
609
609
  .then(() => { })
@@ -1,10 +1,9 @@
1
1
  import { KokimokiStore } from "./kokimoki-store";
2
- import { ZodType } from "zod";
3
- export declare class KokimokiLocalStore<Data> extends KokimokiStore<Data> {
2
+ export declare class KokimokiLocalStore<T> extends KokimokiStore<T> {
4
3
  private readonly localRoomName;
5
4
  private _stateKey?;
6
5
  private get stateKey();
7
- constructor(localRoomName: string, schema: ZodType<Data>, defaultState: Data);
6
+ constructor(localRoomName: string, defaultState: T);
8
7
  getInitialUpdate(appId: string, clientId: string): {
9
8
  roomHash: number;
10
9
  initialUpdate: Uint8Array | undefined;
@@ -11,8 +11,8 @@ export class KokimokiLocalStore extends KokimokiStore {
11
11
  }
12
12
  return this._stateKey;
13
13
  }
14
- constructor(localRoomName, schema, defaultState) {
15
- super(`/l/${localRoomName}`, schema, defaultState, RoomSubscriptionMode.ReadWrite);
14
+ constructor(localRoomName, defaultState) {
15
+ super(`/l/${localRoomName}`, defaultState, RoomSubscriptionMode.ReadWrite);
16
16
  this.localRoomName = localRoomName;
17
17
  // Synchronize doc changes to local storage
18
18
  // TODO: maybe do not serialize full state every time
@@ -1,16 +1,14 @@
1
1
  import * as Y from "yjs";
2
2
  import { RoomSubscriptionMode } from "./room-subscription-mode";
3
3
  import type { KokimokiClient } from "./kokimoki-client";
4
- import { ZodType } from "zod";
5
4
  export declare class KokimokiStore<T> {
6
5
  readonly roomName: string;
7
- readonly schema: ZodType<T>;
8
6
  readonly defaultValue: T;
9
7
  readonly mode: RoomSubscriptionMode;
10
8
  readonly doc: Y.Doc;
11
9
  readonly proxy: T;
12
10
  readonly docRoot: Y.Map<unknown>;
13
- constructor(roomName: string, schema: ZodType<T>, defaultValue: T, mode?: RoomSubscriptionMode);
11
+ constructor(roomName: string, defaultValue: T, mode?: RoomSubscriptionMode);
14
12
  get(): T;
15
13
  subscribe(set: (value: T) => void): () => void;
16
14
  onJoin(client: KokimokiClient): Promise<void>;
@@ -1,19 +1,16 @@
1
1
  import * as Y from "yjs";
2
2
  import { proxy as yjsProxy } from "valtio";
3
3
  import { bind as yjsBind } from "valtio-yjs";
4
- // import DeepProxy from "proxy-deep";
5
4
  import { RoomSubscriptionMode } from "./room-subscription-mode";
6
5
  export class KokimokiStore {
7
6
  roomName;
8
- schema;
9
7
  defaultValue;
10
8
  mode;
11
9
  doc;
12
10
  proxy;
13
11
  docRoot;
14
- constructor(roomName, schema, defaultValue, mode = RoomSubscriptionMode.ReadWrite) {
12
+ constructor(roomName, defaultValue, mode = RoomSubscriptionMode.ReadWrite) {
15
13
  this.roomName = roomName;
16
- this.schema = schema;
17
14
  this.defaultValue = defaultValue;
18
15
  this.mode = mode;
19
16
  // Construct Y doc
@@ -1,6 +1,5 @@
1
1
  import TypedEmitter from 'typed-emitter';
2
2
  import * as Y from 'yjs';
3
- import { ZodType } from 'zod';
4
3
 
5
4
  interface Paginated<T> {
6
5
  items: T[];
@@ -33,13 +32,12 @@ declare enum RoomSubscriptionMode {
33
32
 
34
33
  declare class KokimokiStore<T> {
35
34
  readonly roomName: string;
36
- readonly schema: ZodType<T>;
37
35
  readonly defaultValue: T;
38
36
  readonly mode: RoomSubscriptionMode;
39
37
  readonly doc: Y.Doc;
40
38
  readonly proxy: T;
41
39
  readonly docRoot: Y.Map<unknown>;
42
- constructor(roomName: string, schema: ZodType<T>, defaultValue: T, mode?: RoomSubscriptionMode);
40
+ constructor(roomName: string, defaultValue: T, mode?: RoomSubscriptionMode);
43
41
  get(): T;
44
42
  subscribe(set: (value: T) => void): () => void;
45
43
  onJoin(client: KokimokiClient): Promise<void>;
@@ -54,11 +52,10 @@ declare class KokimokiAwareness<DataT> extends KokimokiStore<{
54
52
  data: DataT;
55
53
  };
56
54
  }> {
57
- readonly dataSchema: ZodType<DataT>;
58
55
  private _data;
59
56
  private _pingInterval;
60
57
  private _kmClients;
61
- constructor(roomName: string, dataSchema: ZodType<DataT>, _data: DataT, mode?: RoomSubscriptionMode, pingTimeout?: number);
58
+ constructor(roomName: string, _data: DataT, mode?: RoomSubscriptionMode, pingTimeout?: number);
62
59
  onJoin(client: KokimokiClient<any>): Promise<void>;
63
60
  onBeforeLeave(client: KokimokiClient<any>): Promise<void>;
64
61
  onLeave(client: KokimokiClient<any>): Promise<void>;
@@ -68,11 +65,11 @@ declare class KokimokiAwareness<DataT> extends KokimokiStore<{
68
65
  setData(data: DataT): Promise<void>;
69
66
  }
70
67
 
71
- declare class KokimokiLocalStore<Data> extends KokimokiStore<Data> {
68
+ declare class KokimokiLocalStore<T> extends KokimokiStore<T> {
72
69
  private readonly localRoomName;
73
70
  private _stateKey?;
74
71
  private get stateKey();
75
- constructor(localRoomName: string, schema: ZodType<Data>, defaultState: Data);
72
+ constructor(localRoomName: string, defaultState: T);
76
73
  getInitialUpdate(appId: string, clientId: string): {
77
74
  roomHash: number;
78
75
  initialUpdate: Uint8Array | undefined;
@@ -150,11 +147,11 @@ declare class KokimokiClient<ClientContextT = any> extends KokimokiClient_base {
150
147
  [K in keyof T]: KokimokiStore<T[K]>;
151
148
  }, handler: (proxies: T) => ReturnT | Promise<ReturnT>): Promise<ReturnT>;
152
149
  close(): Promise<void>;
153
- getRoomHash<T extends ZodType>(store: KokimokiStore<T>): number;
150
+ getRoomHash<T>(store: KokimokiStore<T>): number;
154
151
  /** Initializers */
155
- store<T>(name: string, schema: ZodType<T>, defaultState: T, autoJoin?: boolean): KokimokiStore<T>;
156
- localStore<T>(name: string, schema: ZodType<T>, defaultState: T): KokimokiLocalStore<T>;
157
- awareness<T>(name: string, dataSchema: ZodType<T>, initialData: T, autoJoin?: boolean): KokimokiAwareness<T>;
152
+ store<T>(name: string, defaultState: T, autoJoin?: boolean): KokimokiStore<T>;
153
+ localStore<T>(name: string, defaultState: T): KokimokiLocalStore<T>;
154
+ awareness<T>(name: string, initialData: T, autoJoin?: boolean): KokimokiAwareness<T>;
158
155
  /**
159
156
  * Add a new entry to a leaderboard
160
157
  * @param leaderboardName