@kokimoki/app 1.17.0 → 2.0.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.
Files changed (71) hide show
  1. package/dist/core/index.d.ts +3 -0
  2. package/dist/core/index.js +3 -0
  3. package/dist/core/kokimoki-client.d.ts +361 -0
  4. package/dist/core/kokimoki-client.js +819 -0
  5. package/dist/core/room-subscription-mode.d.ts +5 -0
  6. package/dist/core/room-subscription-mode.js +6 -0
  7. package/dist/core/room-subscription.d.ts +15 -0
  8. package/dist/core/room-subscription.js +53 -0
  9. package/dist/fields.d.ts +110 -0
  10. package/dist/fields.js +158 -0
  11. package/dist/index.d.ts +4 -8
  12. package/dist/index.js +4 -9
  13. package/dist/kokimoki-ai.d.ts +153 -0
  14. package/dist/kokimoki-ai.js +164 -0
  15. package/dist/kokimoki-awareness.d.ts +14 -13
  16. package/dist/kokimoki-awareness.js +41 -33
  17. package/dist/kokimoki-client-refactored.d.ts +80 -0
  18. package/dist/kokimoki-client-refactored.js +400 -0
  19. package/dist/kokimoki-client.d.ts +282 -76
  20. package/dist/kokimoki-client.js +295 -232
  21. package/dist/kokimoki-leaderboard.d.ts +175 -0
  22. package/dist/kokimoki-leaderboard.js +203 -0
  23. package/dist/kokimoki-schema.d.ts +113 -0
  24. package/dist/kokimoki-schema.js +162 -0
  25. package/dist/kokimoki-storage.d.ts +156 -0
  26. package/dist/kokimoki-storage.js +208 -0
  27. package/dist/kokimoki.min.d.ts +775 -110
  28. package/dist/kokimoki.min.js +4088 -2408
  29. package/dist/kokimoki.min.js.map +1 -1
  30. package/dist/llms.txt +657 -0
  31. package/dist/message-queue.d.ts +8 -0
  32. package/dist/message-queue.js +19 -0
  33. package/dist/protocol/ws-message/index.d.ts +3 -0
  34. package/dist/protocol/ws-message/index.js +3 -0
  35. package/dist/protocol/ws-message/reader.d.ts +11 -0
  36. package/dist/protocol/ws-message/reader.js +36 -0
  37. package/dist/protocol/ws-message/type.d.ts +11 -0
  38. package/dist/protocol/ws-message/type.js +12 -0
  39. package/dist/protocol/ws-message/writer.d.ts +9 -0
  40. package/dist/protocol/ws-message/writer.js +45 -0
  41. package/dist/services/index.d.ts +3 -0
  42. package/dist/services/index.js +3 -0
  43. package/dist/services/kokimoki-ai.d.ts +153 -0
  44. package/dist/services/kokimoki-ai.js +164 -0
  45. package/dist/services/kokimoki-leaderboard.d.ts +175 -0
  46. package/dist/services/kokimoki-leaderboard.js +203 -0
  47. package/dist/services/kokimoki-storage.d.ts +155 -0
  48. package/dist/services/kokimoki-storage.js +208 -0
  49. package/dist/stores/index.d.ts +3 -0
  50. package/dist/stores/index.js +3 -0
  51. package/dist/stores/kokimoki-local-store.d.ts +11 -0
  52. package/dist/stores/kokimoki-local-store.js +40 -0
  53. package/dist/stores/kokimoki-store.d.ts +22 -0
  54. package/dist/stores/kokimoki-store.js +117 -0
  55. package/dist/stores/kokimoki-transaction.d.ts +18 -0
  56. package/dist/stores/kokimoki-transaction.js +143 -0
  57. package/dist/synced-schema.d.ts +74 -0
  58. package/dist/synced-schema.js +83 -0
  59. package/dist/synced-store.d.ts +10 -0
  60. package/dist/synced-store.js +9 -0
  61. package/dist/synced-types.d.ts +47 -0
  62. package/dist/synced-types.js +67 -0
  63. package/dist/types/index.d.ts +3 -0
  64. package/dist/types/index.js +3 -0
  65. package/dist/utils/valtio.d.ts +7 -0
  66. package/dist/utils/valtio.js +6 -0
  67. package/dist/version.d.ts +1 -1
  68. package/dist/version.js +2 -1
  69. package/dist/ws-message-type copy.d.ts +6 -0
  70. package/dist/ws-message-type copy.js +7 -0
  71. package/package.json +4 -3
@@ -0,0 +1,117 @@
1
+ import { bind as yjsBind } from "valtio-yjs";
2
+ import { proxy, snapshot, subscribe } from "valtio/vanilla";
3
+ import * as Y from "yjs";
4
+ import { RoomSubscriptionMode } from "../core";
5
+ export class KokimokiStore {
6
+ roomName;
7
+ defaultValue;
8
+ mode;
9
+ doc;
10
+ proxy;
11
+ docRoot;
12
+ connections;
13
+ _unsubscribeConnectionsHandler = () => { };
14
+ constructor(roomName, defaultValue, mode = RoomSubscriptionMode.ReadWrite) {
15
+ this.roomName = roomName;
16
+ this.defaultValue = defaultValue;
17
+ this.mode = mode;
18
+ // "_connections" is a reserved key for tracking connections
19
+ if ("_connections" in defaultValue) {
20
+ throw new Error(`"_connections" is a reserved key in KokimokiStore`);
21
+ }
22
+ // Construct Y doc
23
+ this.doc = new Y.Doc();
24
+ this.docRoot = this.doc.getMap("root");
25
+ // Construct proxy object
26
+ this.proxy = proxy();
27
+ // @ts-ignore
28
+ yjsBind(this.proxy, this.docRoot);
29
+ // Construct connections proxy
30
+ this.connections = proxy({
31
+ connectionIds: new Set(),
32
+ clientIds: new Set(),
33
+ });
34
+ }
35
+ get() {
36
+ return snapshot(this.proxy);
37
+ }
38
+ subscribe(set) {
39
+ const handler = () => set(this.get());
40
+ this.doc.on("update", handler);
41
+ set(this.get());
42
+ return () => this.doc.off("update", handler);
43
+ }
44
+ async onJoin(client) {
45
+ // Update connections whenever _connections changes
46
+ let prevConnectionIds = new Set();
47
+ let prevClientIds = new Set();
48
+ this._unsubscribeConnectionsHandler = subscribe(this.proxy, () => {
49
+ // @ts-ignore
50
+ const newConnectionIds = new Set(
51
+ // @ts-ignore
52
+ Object.keys(this.proxy._connections || {}));
53
+ // Update only if there are changes
54
+ let connectionIdsChanged = false;
55
+ if (newConnectionIds.size !== prevConnectionIds.size) {
56
+ connectionIdsChanged = true;
57
+ }
58
+ if (!connectionIdsChanged) {
59
+ for (const id of newConnectionIds) {
60
+ if (!prevConnectionIds.has(id)) {
61
+ connectionIdsChanged = true;
62
+ break;
63
+ }
64
+ }
65
+ }
66
+ if (!connectionIdsChanged) {
67
+ for (const id of prevConnectionIds) {
68
+ if (!newConnectionIds.has(id)) {
69
+ connectionIdsChanged = true;
70
+ break;
71
+ }
72
+ }
73
+ }
74
+ if (connectionIdsChanged) {
75
+ this.connections.connectionIds = newConnectionIds;
76
+ prevConnectionIds = new Set(newConnectionIds);
77
+ }
78
+ // @ts-ignore
79
+ const newClientIds = new Set(
80
+ // @ts-ignore
81
+ Object.values(this.proxy._connections || {}));
82
+ // Update only if there are changes
83
+ let clientIdsChanged = false;
84
+ if (newClientIds.size !== prevClientIds.size) {
85
+ clientIdsChanged = true;
86
+ }
87
+ if (!clientIdsChanged) {
88
+ for (const id of newClientIds) {
89
+ if (!prevClientIds.has(id)) {
90
+ clientIdsChanged = true;
91
+ break;
92
+ }
93
+ }
94
+ }
95
+ if (!clientIdsChanged) {
96
+ for (const id of prevClientIds) {
97
+ if (!newClientIds.has(id)) {
98
+ clientIdsChanged = true;
99
+ break;
100
+ }
101
+ }
102
+ }
103
+ if (clientIdsChanged) {
104
+ this.connections.clientIds = newClientIds;
105
+ prevClientIds = new Set(newClientIds);
106
+ }
107
+ });
108
+ // Add client to _connections map
109
+ await client.transact([this], ([state]) => {
110
+ state._connections[client.connectionId] = client.id;
111
+ });
112
+ }
113
+ async onBeforeLeave(_client) { }
114
+ async onLeave(_client) {
115
+ this._unsubscribeConnectionsHandler();
116
+ }
117
+ }
@@ -0,0 +1,18 @@
1
+ import { KokimokiStore } from "./kokimoki-store";
2
+ export declare class KokimokiTransaction<T extends object[]> {
3
+ private _updates;
4
+ private _consumeMessagesInRooms;
5
+ private _proxies;
6
+ private _unbindProxies;
7
+ constructor(stores: {
8
+ [K in keyof T]: KokimokiStore<T[K]>;
9
+ });
10
+ getProxies(): T;
11
+ getUpdates(): Promise<{
12
+ updates: {
13
+ roomName: string;
14
+ update: Uint8Array;
15
+ }[];
16
+ consumedMessages: Set<string>;
17
+ }>;
18
+ }
@@ -0,0 +1,143 @@
1
+ import { bind as yjsBind } from "valtio-yjs";
2
+ import { proxy as yjsProxy } from "valtio/vanilla";
3
+ import * as Y from "yjs";
4
+ export class KokimokiTransaction {
5
+ // private _clones = new Map<
6
+ // string,
7
+ // { docClone: Y.Doc; proxyClone: any; unbindProxy: () => void }
8
+ // >();
9
+ _updates = new Map();
10
+ _consumeMessagesInRooms = new Set();
11
+ // private _queueMessageCounter = 0;
12
+ _proxies = [];
13
+ _unbindProxies = [];
14
+ constructor(stores) {
15
+ // Create a proxy for each store
16
+ for (const store of stores) {
17
+ // Clone initial state
18
+ const docClone = new Y.Doc();
19
+ const docRoot = docClone.getMap("root");
20
+ Y.applyUpdate(docClone, Y.encodeStateAsUpdate(store.doc));
21
+ // Set up proxy
22
+ const proxyClone = yjsProxy();
23
+ const unbindProxy = yjsBind(proxyClone, docRoot);
24
+ this._proxies.push(proxyClone);
25
+ this._unbindProxies.push(unbindProxy);
26
+ // Listen for updates
27
+ docClone.on("update", (update) => {
28
+ if (this._updates.has(store.roomName)) {
29
+ const prevUpdate = this._updates.get(store.roomName);
30
+ const nextUpdate = Y.mergeUpdates([prevUpdate, update]);
31
+ this._updates.set(store.roomName, nextUpdate);
32
+ }
33
+ else {
34
+ this._updates.set(store.roomName, update);
35
+ }
36
+ });
37
+ // this._clones.set(store.roomName, { docClone, proxyClone, unbindProxy });
38
+ }
39
+ }
40
+ getProxies() {
41
+ // @ts-ignore
42
+ return this._proxies;
43
+ }
44
+ // private _parseTarget(target: any): {
45
+ // roomName: string;
46
+ // doc: Y.Doc;
47
+ // obj: any;
48
+ // key: string;
49
+ // path: string[];
50
+ // } {
51
+ // return target();
52
+ // }
53
+ // private _parsePath(obj: any, path: string[]) {
54
+ // for (let i = 0; i < path.length - 1; i++) {
55
+ // if (!(path[i] in obj)) {
56
+ // obj[path[i]] = {};
57
+ // }
58
+ // obj = obj[path[i]];
59
+ // }
60
+ // return { obj, key: path[path.length - 1] };
61
+ // }
62
+ // private _getClone(roomName: string, doc: Y.Doc) {
63
+ // if (!this._clones.has(roomName)) {
64
+ // // Clone doc
65
+ // const docClone = new Y.Doc();
66
+ // const docRoot = docClone.getMap("root");
67
+ // Y.applyUpdate(docClone, Y.encodeStateAsUpdate(doc));
68
+ // // Set up proxy
69
+ // const proxyClone = yjsProxy() as any;
70
+ // const unbindProxy = yjsBind(proxyClone, docRoot);
71
+ // // Listen for updates
72
+ // docClone.on("update", (update) => {
73
+ // if (this._updates.has(roomName)) {
74
+ // const prevUpdate = this._updates.get(roomName)!;
75
+ // const nextUpdate = Y.mergeUpdates([prevUpdate, update]);
76
+ // this._updates.set(roomName, nextUpdate);
77
+ // } else {
78
+ // this._updates.set(roomName, update);
79
+ // }
80
+ // });
81
+ // this._clones.set(roomName, { docClone, proxyClone, unbindProxy });
82
+ // }
83
+ // return this._clones.get(roomName)!;
84
+ // }
85
+ // get<T>(target: T): T {
86
+ // const { roomName, doc, path } = this._parseTarget(target);
87
+ // const { proxyClone } = this._getClone(roomName, doc);
88
+ // const { obj, key } = this._parsePath(proxyClone, path);
89
+ // return obj[key];
90
+ // }
91
+ // set<T>(target: T, value: T) {
92
+ // const { roomName, doc, path } = this._parseTarget(target);
93
+ // const { proxyClone } = this._getClone(roomName, doc);
94
+ // const { obj, key } = this._parsePath(proxyClone, path);
95
+ // obj[key] = value;
96
+ // }
97
+ // delete<T>(target: T) {
98
+ // const { roomName, doc, path } = this._parseTarget(target);
99
+ // const { proxyClone } = this._getClone(roomName, doc);
100
+ // const { obj, key } = this._parsePath(proxyClone, path);
101
+ // delete obj[key];
102
+ // }
103
+ // push<T>(target: T[], value: T) {
104
+ // const { roomName, doc, path } = this._parseTarget(target);
105
+ // const { proxyClone } = this._getClone(roomName, doc);
106
+ // const { obj, key } = this._parsePath(proxyClone, path);
107
+ // if (!(key in obj)) {
108
+ // obj[key] = [];
109
+ // }
110
+ // obj[key].push(value);
111
+ // }
112
+ // queueMessage<T>(queue: KokimokiQueue<S.Generic<T>>, payload: T) {
113
+ // const messageId = `${this.kmClient.serverTimestamp()}/${this
114
+ // ._queueMessageCounter++}/${Math.random().toString(36).slice(2)}`;
115
+ // this.set(queue.root[messageId], payload);
116
+ // return messageId;
117
+ // }
118
+ // consumeMessage<T>(queue: KokimokiQueue<S.Generic<T>>, messageId: string) {
119
+ // if (!queue.proxy[messageId]) {
120
+ // throw new Error(
121
+ // `Message ${messageId} does not exist or has already been consumed`
122
+ // );
123
+ // }
124
+ // this.delete(queue.root[messageId]);
125
+ // this._consumeMessagesInRooms.add(queue.roomName);
126
+ // }
127
+ async getUpdates() {
128
+ // Wait for doc update handling to finish
129
+ return await new Promise((resolve) => setTimeout(() => {
130
+ // Clean up
131
+ for (const unbindProxy of this._unbindProxies) {
132
+ unbindProxy();
133
+ }
134
+ // Generates updates
135
+ const updates = Array.from(this._updates.entries()).map(([roomName, update]) => ({
136
+ roomName,
137
+ update,
138
+ }));
139
+ // Done
140
+ resolve({ updates, consumedMessages: this._consumeMessagesInRooms });
141
+ }));
142
+ }
143
+ }
@@ -0,0 +1,74 @@
1
+ export declare abstract class SyncedGeneric<T> {
2
+ abstract get defaultValue(): T;
3
+ abstract set defaultValue(value: T);
4
+ }
5
+ export declare class SyncedNumber extends SyncedGeneric<number> {
6
+ defaultValue: number;
7
+ constructor(defaultValue?: number);
8
+ }
9
+ declare function syncedNumber(defaultValue?: number): SyncedNumber;
10
+ export declare class SyncedString extends SyncedGeneric<string> {
11
+ defaultValue: string;
12
+ constructor(defaultValue?: string);
13
+ }
14
+ declare function syncedString(defaultValue?: string): SyncedString;
15
+ export declare class SyncedBoolean extends SyncedGeneric<boolean> {
16
+ defaultValue: boolean;
17
+ constructor(defaultValue?: boolean);
18
+ }
19
+ declare function syncedBoolean(defaultValue?: boolean): SyncedBoolean;
20
+ export declare class SyncedObject<
21
+ Data extends Record<string, SyncedGeneric<unknown>>,
22
+ > extends SyncedGeneric<{
23
+ [key in keyof Data]: Data[key]["defaultValue"];
24
+ }> {
25
+ fields: Data;
26
+ constructor(fields: Data);
27
+ get defaultValue(): {
28
+ [key in keyof Data]: Data[key]["defaultValue"];
29
+ };
30
+ set defaultValue(value: {
31
+ [key in keyof Data]: Data[key]["defaultValue"];
32
+ });
33
+ }
34
+ declare function syncedObject<
35
+ Data extends Record<string, SyncedGeneric<unknown>>,
36
+ >(schema: Data): SyncedObject<Data>;
37
+ export declare class SyncedMap<T extends SyncedGeneric<unknown>> {
38
+ schema: T;
39
+ defaultValue: {
40
+ [key: string]: T["defaultValue"];
41
+ };
42
+ constructor(
43
+ schema: T,
44
+ defaultValue?: {
45
+ [key: string]: T["defaultValue"];
46
+ },
47
+ );
48
+ }
49
+ declare function syncedMap<T extends SyncedGeneric<unknown>>(
50
+ schema: T,
51
+ defaultValue?: {
52
+ [key: string]: T["defaultValue"];
53
+ },
54
+ ): SyncedMap<T>;
55
+ export declare class SyncedArray<
56
+ T extends SyncedGeneric<unknown>,
57
+ > extends SyncedGeneric<T["defaultValue"][]> {
58
+ schema: T;
59
+ defaultValue: T["defaultValue"][];
60
+ constructor(schema: T, defaultValue?: T["defaultValue"][]);
61
+ }
62
+ declare function syncedArray<T extends SyncedGeneric<unknown>>(
63
+ schema: T,
64
+ defaultValue?: T["defaultValue"][],
65
+ ): SyncedArray<T>;
66
+ export declare const S: {
67
+ number: typeof syncedNumber;
68
+ string: typeof syncedString;
69
+ boolean: typeof syncedBoolean;
70
+ object: typeof syncedObject;
71
+ map: typeof syncedMap;
72
+ array: typeof syncedArray;
73
+ };
74
+ export {};
@@ -0,0 +1,83 @@
1
+ export class SyncedGeneric {}
2
+ export class SyncedNumber extends SyncedGeneric {
3
+ defaultValue;
4
+ constructor(defaultValue = 0) {
5
+ super();
6
+ this.defaultValue = defaultValue;
7
+ }
8
+ }
9
+ function syncedNumber(defaultValue = 0) {
10
+ return new SyncedNumber(defaultValue);
11
+ }
12
+ export class SyncedString extends SyncedGeneric {
13
+ defaultValue;
14
+ constructor(defaultValue = "") {
15
+ super();
16
+ this.defaultValue = defaultValue;
17
+ }
18
+ }
19
+ function syncedString(defaultValue = "") {
20
+ return new SyncedString(defaultValue);
21
+ }
22
+ export class SyncedBoolean extends SyncedGeneric {
23
+ defaultValue;
24
+ constructor(defaultValue = false) {
25
+ super();
26
+ this.defaultValue = defaultValue;
27
+ }
28
+ }
29
+ function syncedBoolean(defaultValue = false) {
30
+ return new SyncedBoolean(defaultValue);
31
+ }
32
+ export class SyncedObject extends SyncedGeneric {
33
+ fields;
34
+ constructor(fields) {
35
+ super();
36
+ this.fields = fields;
37
+ }
38
+ get defaultValue() {
39
+ return Object.entries(this.fields).reduce((acc, [key, field]) => {
40
+ acc[key] = field.defaultValue;
41
+ return acc;
42
+ }, {});
43
+ }
44
+ set defaultValue(value) {
45
+ for (const [key, field] of Object.entries(this.fields)) {
46
+ field.defaultValue = value[key];
47
+ }
48
+ }
49
+ }
50
+ function syncedObject(schema) {
51
+ return new SyncedObject(schema);
52
+ }
53
+ export class SyncedMap {
54
+ schema;
55
+ defaultValue;
56
+ constructor(schema, defaultValue = {}) {
57
+ this.schema = schema;
58
+ this.defaultValue = defaultValue;
59
+ }
60
+ }
61
+ function syncedMap(schema, defaultValue = {}) {
62
+ return new SyncedMap(schema, defaultValue);
63
+ }
64
+ export class SyncedArray extends SyncedGeneric {
65
+ schema;
66
+ defaultValue;
67
+ constructor(schema, defaultValue = []) {
68
+ super();
69
+ this.schema = schema;
70
+ this.defaultValue = defaultValue;
71
+ }
72
+ }
73
+ function syncedArray(schema, defaultValue = []) {
74
+ return new SyncedArray(schema, defaultValue);
75
+ }
76
+ export const S = {
77
+ number: syncedNumber,
78
+ string: syncedString,
79
+ boolean: syncedBoolean,
80
+ object: syncedObject,
81
+ map: syncedMap,
82
+ array: syncedArray,
83
+ };
@@ -0,0 +1,10 @@
1
+ import type * as Y from "yjs";
2
+ import type {
3
+ DocTypeDescription,
4
+ MappedTypeDescription,
5
+ } from "@syncedstore/core/types/doc";
6
+ export declare class SyncedStore<T extends DocTypeDescription> {
7
+ readonly data: MappedTypeDescription<T>;
8
+ readonly doc: Y.Doc;
9
+ constructor(initialState: T);
10
+ }
@@ -0,0 +1,9 @@
1
+ import { syncedStore, getYjsDoc } from "@syncedstore/core";
2
+ export class SyncedStore {
3
+ data;
4
+ doc;
5
+ constructor(initialState) {
6
+ this.data = syncedStore(initialState);
7
+ this.doc = getYjsDoc(this.data);
8
+ }
9
+ }
@@ -0,0 +1,47 @@
1
+ export declare abstract class SyncedGeneric<T> {
2
+ abstract get defaultValue(): T;
3
+ abstract set defaultValue(value: T);
4
+ }
5
+ export declare class SyncedNumber extends SyncedGeneric<number> {
6
+ defaultValue: number;
7
+ constructor(defaultValue?: number);
8
+ }
9
+ export declare function syncedNumber(defaultValue?: number): SyncedNumber;
10
+ export declare class SyncedString extends SyncedGeneric<string> {
11
+ defaultValue: string;
12
+ constructor(defaultValue?: string);
13
+ }
14
+ export declare function syncedString(defaultValue?: string): SyncedString;
15
+ export declare class SyncedBoolean extends SyncedGeneric<boolean> {
16
+ defaultValue: boolean;
17
+ constructor(defaultValue?: boolean);
18
+ }
19
+ export declare function syncedBoolean(defaultValue?: boolean): SyncedBoolean;
20
+ export declare class SyncedMap<
21
+ Data extends Record<string, SyncedGeneric<unknown>>,
22
+ > extends SyncedGeneric<{
23
+ [key in keyof Data]: Data[key]["defaultValue"];
24
+ }> {
25
+ fields: Data;
26
+ constructor(fields: Data);
27
+ get defaultValue(): {
28
+ [key in keyof Data]: Data[key]["defaultValue"];
29
+ };
30
+ set defaultValue(value: {
31
+ [key in keyof Data]: Data[key]["defaultValue"];
32
+ });
33
+ }
34
+ export declare function syncedMap<
35
+ T extends Record<string, SyncedGeneric<unknown>>,
36
+ >(schema: T): SyncedMap<T>;
37
+ export declare class SyncedArray<
38
+ T extends SyncedGeneric<unknown>,
39
+ > extends SyncedGeneric<T["defaultValue"][]> {
40
+ schema: T;
41
+ defaultValue: T["defaultValue"][];
42
+ constructor(schema: T, defaultValue?: T["defaultValue"][]);
43
+ }
44
+ export declare function syncedArray<T extends SyncedGeneric<unknown>>(
45
+ schema: T,
46
+ defaultValue?: T["defaultValue"][],
47
+ ): SyncedArray<T>;
@@ -0,0 +1,67 @@
1
+ import * as Y from "yjs";
2
+ import { proxy as yjsProxy } from "valtio";
3
+ import { bind as yjsBind } from "valtio-yjs";
4
+ export class SyncedGeneric {}
5
+ export class SyncedNumber extends SyncedGeneric {
6
+ defaultValue;
7
+ constructor(defaultValue = 0) {
8
+ super();
9
+ this.defaultValue = defaultValue;
10
+ }
11
+ }
12
+ export function syncedNumber(defaultValue = 0) {
13
+ return new SyncedNumber(defaultValue);
14
+ }
15
+ export class SyncedString extends SyncedGeneric {
16
+ defaultValue;
17
+ constructor(defaultValue = "") {
18
+ super();
19
+ this.defaultValue = defaultValue;
20
+ }
21
+ }
22
+ export function syncedString(defaultValue = "") {
23
+ return new SyncedString(defaultValue);
24
+ }
25
+ export class SyncedBoolean extends SyncedGeneric {
26
+ defaultValue;
27
+ constructor(defaultValue = false) {
28
+ super();
29
+ this.defaultValue = defaultValue;
30
+ }
31
+ }
32
+ export function syncedBoolean(defaultValue = false) {
33
+ return new SyncedBoolean(defaultValue);
34
+ }
35
+ export class SyncedMap extends SyncedGeneric {
36
+ fields;
37
+ constructor(fields) {
38
+ super();
39
+ this.fields = fields;
40
+ }
41
+ get defaultValue() {
42
+ return Object.entries(this.fields).reduce((acc, [key, field]) => {
43
+ acc[key] = field.defaultValue;
44
+ return acc;
45
+ }, {});
46
+ }
47
+ set defaultValue(value) {
48
+ for (const [key, field] of Object.entries(this.fields)) {
49
+ field.defaultValue = value[key];
50
+ }
51
+ }
52
+ }
53
+ export function syncedMap(schema) {
54
+ return new SyncedMap(schema);
55
+ }
56
+ export class SyncedArray extends SyncedGeneric {
57
+ schema;
58
+ defaultValue;
59
+ constructor(schema, defaultValue = []) {
60
+ super();
61
+ this.schema = schema;
62
+ this.defaultValue = defaultValue;
63
+ }
64
+ }
65
+ export function syncedArray(schema, defaultValue = []) {
66
+ return new SyncedArray(schema, defaultValue);
67
+ }
@@ -0,0 +1,3 @@
1
+ export * from "./common";
2
+ export * from "./events";
3
+ export * from "./upload";
@@ -0,0 +1,3 @@
1
+ export * from "./common";
2
+ export * from "./events";
3
+ export * from "./upload";
@@ -0,0 +1,7 @@
1
+ import "valtio";
2
+ declare module "valtio" {
3
+ function useSnapshot<T extends object>(p: T): T;
4
+ }
5
+ export { proxy, ref, snapshot, subscribe, useSnapshot } from "valtio";
6
+ export { derive, underive } from "derive-valtio";
7
+ export { devtools, subscribeKey, useProxy, watch } from "valtio/utils";
@@ -0,0 +1,6 @@
1
+ import "valtio";
2
+ // Core Valtio exports
3
+ export { proxy, ref, snapshot, subscribe, useSnapshot } from "valtio";
4
+ // Valtio utilities
5
+ export { derive, underive } from "derive-valtio";
6
+ export { devtools, subscribeKey, useProxy, watch } from "valtio/utils";
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const KOKIMOKI_APP_VERSION = "1.17.0";
1
+ export declare const KOKIMOKI_APP_VERSION = "2.0.1";
package/dist/version.js CHANGED
@@ -1 +1,2 @@
1
- export const KOKIMOKI_APP_VERSION = "1.17.0";
1
+ // Auto-generated file. Do not edit manually.
2
+ export const KOKIMOKI_APP_VERSION = '2.0.1';
@@ -0,0 +1,6 @@
1
+ export declare enum WsMessageType {
2
+ SubscribeReq = 1,
3
+ SubscribeRes = 2,
4
+ Transaction = 3,
5
+ RoomUpdate = 4,
6
+ }
@@ -0,0 +1,7 @@
1
+ export var WsMessageType;
2
+ (function (WsMessageType) {
3
+ WsMessageType[(WsMessageType["SubscribeReq"] = 1)] = "SubscribeReq";
4
+ WsMessageType[(WsMessageType["SubscribeRes"] = 2)] = "SubscribeRes";
5
+ WsMessageType[(WsMessageType["Transaction"] = 3)] = "Transaction";
6
+ WsMessageType[(WsMessageType["RoomUpdate"] = 4)] = "RoomUpdate";
7
+ })(WsMessageType || (WsMessageType = {}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kokimoki/app",
3
- "version": "1.17.0",
3
+ "version": "2.0.1",
4
4
  "type": "module",
5
5
  "description": "Kokimoki app",
6
6
  "main": "dist/index.js",
@@ -14,9 +14,9 @@
14
14
  },
15
15
  "scripts": {
16
16
  "test": "NODE_OPTIONS='--import tsx' mocha",
17
- "prebuild": "node -p \"'export const KOKIMOKI_APP_VERSION = ' + JSON.stringify(require('./package.json').version) + ';'\" > src/version.ts",
17
+ "prebuild": "node scripts/generate-version.js",
18
18
  "build": "tsc",
19
- "postbuild": "rollup --config",
19
+ "postbuild": "rollup --config && cp docs/instructions.md dist/llms.txt",
20
20
  "dev": "tsc -w",
21
21
  "docs": "typedoc src/index.ts",
22
22
  "rollup": "rollup --config"
@@ -44,6 +44,7 @@
44
44
  "typescript": "^5.1.6"
45
45
  },
46
46
  "dependencies": {
47
+ "derive-valtio": "^0.2.0",
47
48
  "events": "^3.3.0",
48
49
  "farmhash-modern": "^1.1.0",
49
50
  "typed-emitter": "^2.1.0",