@kokimoki/app 3.1.3 → 3.1.5
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 -2
- package/dist/core/kokimoki-client.d.ts +4 -4
- package/dist/core/kokimoki-client.js +4 -4
- package/dist/index.d.ts +1 -2
- package/dist/index.js +1 -2
- package/dist/utils/valtio.d.ts +2 -5
- package/dist/utils/valtio.js +4 -2
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/docs/kokimoki-ai.instructions.md +4 -2
- package/docs/kokimoki-dynamic-stores.instructions.md +3 -3
- package/docs/kokimoki-i18n.instructions.md +1 -1
- package/docs/kokimoki-sdk.instructions.md +46 -7
- package/package.json +15 -2
- package/dist/fields.d.ts +0 -110
- package/dist/fields.js +0 -158
- package/dist/kokimoki-ai.d.ts +0 -153
- package/dist/kokimoki-ai.js +0 -164
- package/dist/kokimoki-awareness.d.ts +0 -21
- package/dist/kokimoki-awareness.js +0 -48
- package/dist/kokimoki-client-refactored.d.ts +0 -80
- package/dist/kokimoki-client-refactored.js +0 -400
- package/dist/kokimoki-client.d.ts +0 -362
- package/dist/kokimoki-client.js +0 -823
- package/dist/kokimoki-leaderboard.d.ts +0 -175
- package/dist/kokimoki-leaderboard.js +0 -203
- package/dist/kokimoki-local-store.d.ts +0 -11
- package/dist/kokimoki-local-store.js +0 -40
- package/dist/kokimoki-queue.d.ts +0 -0
- package/dist/kokimoki-queue.js +0 -38
- package/dist/kokimoki-req-res.d.ts +0 -0
- package/dist/kokimoki-req-res.js +0 -198
- package/dist/kokimoki-schema.d.ts +0 -113
- package/dist/kokimoki-schema.js +0 -162
- package/dist/kokimoki-storage.d.ts +0 -156
- package/dist/kokimoki-storage.js +0 -208
- package/dist/kokimoki-store.d.ts +0 -23
- package/dist/kokimoki-store.js +0 -117
- package/dist/kokimoki-transaction.d.ts +0 -18
- package/dist/kokimoki-transaction.js +0 -143
- package/dist/kokimoki.min.d.ts +0 -1244
- package/dist/kokimoki.min.js +0 -19108
- package/dist/kokimoki.min.js.map +0 -1
- package/dist/llms.txt +0 -665
- package/dist/message-queue.d.ts +0 -8
- package/dist/message-queue.js +0 -19
- package/dist/room-subscription-mode.d.ts +0 -5
- package/dist/room-subscription-mode.js +0 -6
- package/dist/room-subscription.d.ts +0 -15
- package/dist/room-subscription.js +0 -52
- package/dist/synced-schema.d.ts +0 -74
- package/dist/synced-schema.js +0 -83
- package/dist/synced-store.d.ts +0 -10
- package/dist/synced-store.js +0 -9
- package/dist/synced-types.d.ts +0 -47
- package/dist/synced-types.js +0 -67
- package/dist/ws-message-reader.d.ts +0 -11
- package/dist/ws-message-reader.js +0 -36
- package/dist/ws-message-type copy.d.ts +0 -6
- package/dist/ws-message-type copy.js +0 -7
- package/dist/ws-message-type.d.ts +0 -11
- package/dist/ws-message-type.js +0 -12
- package/dist/ws-message-writer.d.ts +0 -9
- package/dist/ws-message-writer.js +0 -45
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
export declare namespace KokimokiSchema {
|
|
2
|
-
abstract class Generic<T> {
|
|
3
|
-
abstract get defaultValue(): T;
|
|
4
|
-
abstract set defaultValue(value: T);
|
|
5
|
-
}
|
|
6
|
-
class Number extends Generic<number> {
|
|
7
|
-
defaultValue: number;
|
|
8
|
-
constructor(defaultValue?: number);
|
|
9
|
-
}
|
|
10
|
-
function number(defaultValue?: number): Number;
|
|
11
|
-
class String extends Generic<string> {
|
|
12
|
-
defaultValue: string;
|
|
13
|
-
constructor(defaultValue?: string);
|
|
14
|
-
}
|
|
15
|
-
function string(defaultValue?: string): String;
|
|
16
|
-
class Boolean extends Generic<boolean> {
|
|
17
|
-
defaultValue: boolean;
|
|
18
|
-
constructor(defaultValue?: boolean);
|
|
19
|
-
}
|
|
20
|
-
function boolean(defaultValue?: boolean): Boolean;
|
|
21
|
-
class Struct<Data extends Record<string, Generic<unknown>>> extends Generic<{
|
|
22
|
-
[key in keyof Data]: Data[key]["defaultValue"];
|
|
23
|
-
}> {
|
|
24
|
-
fields: Data;
|
|
25
|
-
constructor(fields: Data);
|
|
26
|
-
get defaultValue(): {
|
|
27
|
-
[key in keyof Data]: Data[key]["defaultValue"];
|
|
28
|
-
};
|
|
29
|
-
set defaultValue(value: {
|
|
30
|
-
[key in keyof Data]: Data[key]["defaultValue"];
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
function struct<Data extends Record<string, Generic<unknown>>>(
|
|
34
|
-
schema: Data,
|
|
35
|
-
): Struct<Data>;
|
|
36
|
-
class Dict<T extends Generic<unknown>> {
|
|
37
|
-
schema: T;
|
|
38
|
-
defaultValue: {
|
|
39
|
-
[key: string]: T["defaultValue"];
|
|
40
|
-
};
|
|
41
|
-
constructor(
|
|
42
|
-
schema: T,
|
|
43
|
-
defaultValue?: {
|
|
44
|
-
[key: string]: T["defaultValue"];
|
|
45
|
-
},
|
|
46
|
-
);
|
|
47
|
-
}
|
|
48
|
-
function dict<T extends Generic<unknown>>(
|
|
49
|
-
schema: T,
|
|
50
|
-
defaultValue?: {
|
|
51
|
-
[key: string]: T["defaultValue"];
|
|
52
|
-
},
|
|
53
|
-
): Dict<T>;
|
|
54
|
-
class List<T extends Generic<unknown>> extends Generic<T["defaultValue"][]> {
|
|
55
|
-
schema: T;
|
|
56
|
-
defaultValue: T["defaultValue"][];
|
|
57
|
-
constructor(schema: T, defaultValue?: T["defaultValue"][]);
|
|
58
|
-
}
|
|
59
|
-
function list<T extends Generic<unknown>>(
|
|
60
|
-
schema: T,
|
|
61
|
-
defaultValue?: T["defaultValue"][],
|
|
62
|
-
): List<T>;
|
|
63
|
-
/**
|
|
64
|
-
* Nullable
|
|
65
|
-
*/
|
|
66
|
-
class Nullable<T extends Generic<unknown>> extends Generic<
|
|
67
|
-
T["defaultValue"] | null
|
|
68
|
-
> {
|
|
69
|
-
schema: T;
|
|
70
|
-
defaultValue: T["defaultValue"] | null;
|
|
71
|
-
constructor(schema: T, defaultValue: T["defaultValue"] | null);
|
|
72
|
-
}
|
|
73
|
-
function nullable<T extends Generic<unknown>>(
|
|
74
|
-
schema: T,
|
|
75
|
-
defaultValue?: T["defaultValue"] | null,
|
|
76
|
-
): Nullable<T>;
|
|
77
|
-
class StringEnum<T extends readonly string[]> extends Generic<string> {
|
|
78
|
-
readonly options: T;
|
|
79
|
-
defaultValue: T[number];
|
|
80
|
-
constructor(options: T, defaultValue: T[number]);
|
|
81
|
-
}
|
|
82
|
-
function stringEnum<T extends readonly string[]>(
|
|
83
|
-
options: T,
|
|
84
|
-
defaultValue: T[number],
|
|
85
|
-
): StringEnum<T>;
|
|
86
|
-
class StringConst<T extends string> extends Generic<string> {
|
|
87
|
-
readonly defaultValue: T;
|
|
88
|
-
constructor(defaultValue: T);
|
|
89
|
-
}
|
|
90
|
-
function stringConst<T extends string>(defaultValue: T): StringConst<T>;
|
|
91
|
-
class AnyOf<T extends readonly Generic<unknown>[]> extends Generic<
|
|
92
|
-
T[number]["defaultValue"]
|
|
93
|
-
> {
|
|
94
|
-
readonly schemas: T;
|
|
95
|
-
defaultValue: T[number]["defaultValue"];
|
|
96
|
-
constructor(schemas: T, defaultValue: T[number]["defaultValue"]);
|
|
97
|
-
}
|
|
98
|
-
function anyOf<T extends readonly Generic<unknown>[]>(
|
|
99
|
-
schemas: T,
|
|
100
|
-
defaultValue: T[number]["defaultValue"],
|
|
101
|
-
): AnyOf<T>;
|
|
102
|
-
class Optional<T extends Generic<unknown>> extends Generic<
|
|
103
|
-
T["defaultValue"] | undefined
|
|
104
|
-
> {
|
|
105
|
-
schema: T;
|
|
106
|
-
defaultValue: T["defaultValue"] | undefined;
|
|
107
|
-
constructor(schema: T, defaultValue?: T["defaultValue"] | undefined);
|
|
108
|
-
}
|
|
109
|
-
function optional<T extends Generic<unknown>>(
|
|
110
|
-
schema: T,
|
|
111
|
-
defaultValue?: T["defaultValue"] | undefined,
|
|
112
|
-
): Optional<T>;
|
|
113
|
-
}
|
package/dist/kokimoki-schema.js
DELETED
|
@@ -1,162 +0,0 @@
|
|
|
1
|
-
export var KokimokiSchema;
|
|
2
|
-
(function (KokimokiSchema) {
|
|
3
|
-
class Generic {}
|
|
4
|
-
KokimokiSchema.Generic = Generic;
|
|
5
|
-
class Number extends Generic {
|
|
6
|
-
defaultValue;
|
|
7
|
-
constructor(defaultValue = 0) {
|
|
8
|
-
super();
|
|
9
|
-
this.defaultValue = defaultValue;
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
KokimokiSchema.Number = Number;
|
|
13
|
-
function number(defaultValue = 0) {
|
|
14
|
-
return new Number(defaultValue);
|
|
15
|
-
}
|
|
16
|
-
KokimokiSchema.number = number;
|
|
17
|
-
class String extends Generic {
|
|
18
|
-
defaultValue;
|
|
19
|
-
constructor(defaultValue = "") {
|
|
20
|
-
super();
|
|
21
|
-
this.defaultValue = defaultValue;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
KokimokiSchema.String = String;
|
|
25
|
-
function string(defaultValue = "") {
|
|
26
|
-
return new String(defaultValue);
|
|
27
|
-
}
|
|
28
|
-
KokimokiSchema.string = string;
|
|
29
|
-
class Boolean extends Generic {
|
|
30
|
-
defaultValue;
|
|
31
|
-
constructor(defaultValue = false) {
|
|
32
|
-
super();
|
|
33
|
-
this.defaultValue = defaultValue;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
KokimokiSchema.Boolean = Boolean;
|
|
37
|
-
function boolean(defaultValue = false) {
|
|
38
|
-
return new Boolean(defaultValue);
|
|
39
|
-
}
|
|
40
|
-
KokimokiSchema.boolean = boolean;
|
|
41
|
-
class Struct extends Generic {
|
|
42
|
-
fields;
|
|
43
|
-
constructor(fields) {
|
|
44
|
-
super();
|
|
45
|
-
this.fields = fields;
|
|
46
|
-
}
|
|
47
|
-
get defaultValue() {
|
|
48
|
-
return Object.entries(this.fields).reduce((acc, [key, field]) => {
|
|
49
|
-
acc[key] = field.defaultValue;
|
|
50
|
-
return acc;
|
|
51
|
-
}, {});
|
|
52
|
-
}
|
|
53
|
-
set defaultValue(value) {
|
|
54
|
-
for (const [key, field] of Object.entries(this.fields)) {
|
|
55
|
-
field.defaultValue = value[key];
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
KokimokiSchema.Struct = Struct;
|
|
60
|
-
function struct(schema) {
|
|
61
|
-
return new Struct(schema);
|
|
62
|
-
}
|
|
63
|
-
KokimokiSchema.struct = struct;
|
|
64
|
-
class Dict {
|
|
65
|
-
schema;
|
|
66
|
-
defaultValue;
|
|
67
|
-
constructor(schema, defaultValue = {}) {
|
|
68
|
-
this.schema = schema;
|
|
69
|
-
this.defaultValue = defaultValue;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
KokimokiSchema.Dict = Dict;
|
|
73
|
-
function dict(schema, defaultValue = {}) {
|
|
74
|
-
return new Dict(schema, defaultValue);
|
|
75
|
-
}
|
|
76
|
-
KokimokiSchema.dict = dict;
|
|
77
|
-
class List extends Generic {
|
|
78
|
-
schema;
|
|
79
|
-
defaultValue;
|
|
80
|
-
constructor(schema, defaultValue = []) {
|
|
81
|
-
super();
|
|
82
|
-
this.schema = schema;
|
|
83
|
-
this.defaultValue = defaultValue;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
KokimokiSchema.List = List;
|
|
87
|
-
function list(schema, defaultValue = []) {
|
|
88
|
-
return new List(schema, defaultValue);
|
|
89
|
-
}
|
|
90
|
-
KokimokiSchema.list = list;
|
|
91
|
-
/**
|
|
92
|
-
* Nullable
|
|
93
|
-
*/
|
|
94
|
-
class Nullable extends Generic {
|
|
95
|
-
schema;
|
|
96
|
-
defaultValue;
|
|
97
|
-
constructor(schema, defaultValue) {
|
|
98
|
-
super();
|
|
99
|
-
this.schema = schema;
|
|
100
|
-
this.defaultValue = defaultValue;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
KokimokiSchema.Nullable = Nullable;
|
|
104
|
-
function nullable(schema, defaultValue = null) {
|
|
105
|
-
return new Nullable(schema, defaultValue);
|
|
106
|
-
}
|
|
107
|
-
KokimokiSchema.nullable = nullable;
|
|
108
|
-
class StringEnum extends Generic {
|
|
109
|
-
options;
|
|
110
|
-
defaultValue;
|
|
111
|
-
constructor(options, defaultValue) {
|
|
112
|
-
super();
|
|
113
|
-
this.options = options;
|
|
114
|
-
this.defaultValue = defaultValue;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
KokimokiSchema.StringEnum = StringEnum;
|
|
118
|
-
function stringEnum(options, defaultValue) {
|
|
119
|
-
return new StringEnum(options, defaultValue);
|
|
120
|
-
}
|
|
121
|
-
KokimokiSchema.stringEnum = stringEnum;
|
|
122
|
-
class StringConst extends Generic {
|
|
123
|
-
defaultValue;
|
|
124
|
-
constructor(defaultValue) {
|
|
125
|
-
super();
|
|
126
|
-
this.defaultValue = defaultValue;
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
KokimokiSchema.StringConst = StringConst;
|
|
130
|
-
function stringConst(defaultValue) {
|
|
131
|
-
return new StringConst(defaultValue);
|
|
132
|
-
}
|
|
133
|
-
KokimokiSchema.stringConst = stringConst;
|
|
134
|
-
class AnyOf extends Generic {
|
|
135
|
-
schemas;
|
|
136
|
-
defaultValue;
|
|
137
|
-
constructor(schemas, defaultValue) {
|
|
138
|
-
super();
|
|
139
|
-
this.schemas = schemas;
|
|
140
|
-
this.defaultValue = defaultValue;
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
KokimokiSchema.AnyOf = AnyOf;
|
|
144
|
-
function anyOf(schemas, defaultValue) {
|
|
145
|
-
return new AnyOf(schemas, defaultValue);
|
|
146
|
-
}
|
|
147
|
-
KokimokiSchema.anyOf = anyOf;
|
|
148
|
-
class Optional extends Generic {
|
|
149
|
-
schema;
|
|
150
|
-
defaultValue;
|
|
151
|
-
constructor(schema, defaultValue = undefined) {
|
|
152
|
-
super();
|
|
153
|
-
this.schema = schema;
|
|
154
|
-
this.defaultValue = defaultValue;
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
KokimokiSchema.Optional = Optional;
|
|
158
|
-
function optional(schema, defaultValue = undefined) {
|
|
159
|
-
return new Optional(schema, defaultValue);
|
|
160
|
-
}
|
|
161
|
-
KokimokiSchema.optional = optional;
|
|
162
|
-
})(KokimokiSchema || (KokimokiSchema = {}));
|
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
import { KokimokiClient } from "./kokimoki-client";
|
|
2
|
-
import { Paginated } from "./types/common";
|
|
3
|
-
import { Upload } from "./types/upload";
|
|
4
|
-
/**
|
|
5
|
-
* Kokimoki Storage Service
|
|
6
|
-
*
|
|
7
|
-
* Provides file upload and management capabilities for game applications. Ideal for media files
|
|
8
|
-
* (images, videos, audio) and other data not suitable for real-time stores (JSON, text files).
|
|
9
|
-
*
|
|
10
|
-
* **Key Features:**
|
|
11
|
-
* - Upload files to cloud storage with CDN delivery
|
|
12
|
-
* - Tag-based organization and filtering
|
|
13
|
-
* - Query uploads by client, MIME type, or tags
|
|
14
|
-
* - Pagination support for large collections
|
|
15
|
-
* - Public CDN URLs for direct access
|
|
16
|
-
*
|
|
17
|
-
* **Common Use Cases:**
|
|
18
|
-
* - Player avatars and profile images
|
|
19
|
-
* - Game screenshots and replays
|
|
20
|
-
* - User-generated content
|
|
21
|
-
* - Asset uploads (levels, maps, custom skins)
|
|
22
|
-
* - JSON configuration files
|
|
23
|
-
*
|
|
24
|
-
* Access via `kmClient.storage`
|
|
25
|
-
*
|
|
26
|
-
* @example
|
|
27
|
-
* ```typescript
|
|
28
|
-
* // Upload an image
|
|
29
|
-
* const upload = await kmClient.storage.upload('avatar.jpg', imageBlob, ['profile']);
|
|
30
|
-
*
|
|
31
|
-
* // Query user's uploads
|
|
32
|
-
* const myUploads = await kmClient.storage.listUploads({
|
|
33
|
-
* clientId: kmClient.id
|
|
34
|
-
* });
|
|
35
|
-
*
|
|
36
|
-
* // Use in store
|
|
37
|
-
* await kmClient.transact([store], (state) => {
|
|
38
|
-
* state.playerAvatar = upload.url;
|
|
39
|
-
* });
|
|
40
|
-
* ```
|
|
41
|
-
*/
|
|
42
|
-
export declare class KokimokiStorage {
|
|
43
|
-
private readonly client;
|
|
44
|
-
constructor(client: KokimokiClient);
|
|
45
|
-
private createUpload;
|
|
46
|
-
private uploadChunks;
|
|
47
|
-
private completeUpload;
|
|
48
|
-
/**
|
|
49
|
-
* Upload a file to cloud storage.
|
|
50
|
-
*
|
|
51
|
-
* Uploads a file (Blob) to Kokimoki storage and returns an Upload object with a public CDN URL.
|
|
52
|
-
* Files are automatically chunked for efficient upload. The returned URL can be used directly
|
|
53
|
-
* in your application (e.g., in img tags or store state).
|
|
54
|
-
*
|
|
55
|
-
* @param name The filename for the upload
|
|
56
|
-
* @param blob The Blob object containing the file data
|
|
57
|
-
* @param tags Optional array of tags for organizing and filtering uploads (default: [])
|
|
58
|
-
* @returns A promise resolving to the Upload object with CDN URL and metadata
|
|
59
|
-
*
|
|
60
|
-
* @example
|
|
61
|
-
* ```typescript
|
|
62
|
-
* // Upload image with tags
|
|
63
|
-
* const upload = await kmClient.storage.upload(
|
|
64
|
-
* 'avatar.jpg',
|
|
65
|
-
* imageBlob,
|
|
66
|
-
* ['profile', 'avatar']
|
|
67
|
-
* );
|
|
68
|
-
*
|
|
69
|
-
* // Use the CDN URL
|
|
70
|
-
* console.log(upload.url); // https://cdn.kokimoki.com/...
|
|
71
|
-
*
|
|
72
|
-
* // Store in game state
|
|
73
|
-
* await kmClient.transact([store], (state) => {
|
|
74
|
-
* state.players[kmClient.id].avatar = upload.url;
|
|
75
|
-
* });
|
|
76
|
-
* ```
|
|
77
|
-
*/
|
|
78
|
-
upload(name: string, blob: Blob, tags?: string[]): Promise<Upload>;
|
|
79
|
-
/**
|
|
80
|
-
* Update metadata for an existing upload.
|
|
81
|
-
*
|
|
82
|
-
* Allows you to replace the tags associated with an upload. Useful for reorganizing
|
|
83
|
-
* or recategorizing uploaded files.
|
|
84
|
-
*
|
|
85
|
-
* @param id The upload ID to update
|
|
86
|
-
* @param update Object containing the new tags array
|
|
87
|
-
* @returns A promise resolving to the updated Upload object
|
|
88
|
-
*
|
|
89
|
-
* @example
|
|
90
|
-
* ```typescript
|
|
91
|
-
* // Update tags
|
|
92
|
-
* const updated = await kmClient.storage.updateUpload(upload.id, {
|
|
93
|
-
* tags: ['archived', 'old-profile']
|
|
94
|
-
* });
|
|
95
|
-
* ```
|
|
96
|
-
*/
|
|
97
|
-
updateUpload(id: string, update: {
|
|
98
|
-
tags?: string[];
|
|
99
|
-
}): Promise<Upload>;
|
|
100
|
-
/**
|
|
101
|
-
* Query uploaded files with filtering and pagination.
|
|
102
|
-
*
|
|
103
|
-
* Retrieves a list of uploads matching the specified criteria. Supports filtering by
|
|
104
|
-
* client (uploader), MIME types, and tags. Use pagination for large collections.
|
|
105
|
-
*
|
|
106
|
-
* @param filter Optional filter criteria
|
|
107
|
-
* @param filter.clientId Filter by uploader's client ID
|
|
108
|
-
* @param filter.mimeTypes Filter by MIME types (e.g., ['image/jpeg', 'image/png'])
|
|
109
|
-
* @param filter.tags Filter by tags (all specified tags must match)
|
|
110
|
-
* @param skip Number of results to skip for pagination (default: 0)
|
|
111
|
-
* @param limit Maximum number of results to return (default: 100)
|
|
112
|
-
* @returns A promise resolving to paginated Upload results with total count
|
|
113
|
-
*
|
|
114
|
-
* @example
|
|
115
|
-
* ```typescript
|
|
116
|
-
* // Get current user's images
|
|
117
|
-
* const myImages = await kmClient.storage.listUploads({
|
|
118
|
-
* clientId: kmClient.id,
|
|
119
|
-
* mimeTypes: ['image/jpeg', 'image/png']
|
|
120
|
-
* });
|
|
121
|
-
*
|
|
122
|
-
* // Get all profile avatars
|
|
123
|
-
* const avatars = await kmClient.storage.listUploads({
|
|
124
|
-
* tags: ['profile', 'avatar']
|
|
125
|
-
* });
|
|
126
|
-
*
|
|
127
|
-
* // Pagination
|
|
128
|
-
* const page2 = await kmClient.storage.listUploads({}, 10, 10);
|
|
129
|
-
* ```
|
|
130
|
-
*/
|
|
131
|
-
listUploads(filter?: {
|
|
132
|
-
clientId?: string;
|
|
133
|
-
mimeTypes?: string[];
|
|
134
|
-
tags?: string[];
|
|
135
|
-
}, skip?: number, limit?: number): Promise<Paginated<Upload>>;
|
|
136
|
-
/**
|
|
137
|
-
* Permanently delete an uploaded file.
|
|
138
|
-
*
|
|
139
|
-
* Removes the file from cloud storage and the CDN. The URL will no longer be accessible.
|
|
140
|
-
* This operation cannot be undone.
|
|
141
|
-
*
|
|
142
|
-
* @param id The upload ID to delete
|
|
143
|
-
* @returns A promise resolving to deletion confirmation
|
|
144
|
-
*
|
|
145
|
-
* @example
|
|
146
|
-
* ```typescript
|
|
147
|
-
* // Delete an upload
|
|
148
|
-
* const result = await kmClient.storage.deleteUpload(upload.id);
|
|
149
|
-
* console.log(`Deleted: ${result.deletedCount} file(s)`);
|
|
150
|
-
* ```
|
|
151
|
-
*/
|
|
152
|
-
deleteUpload(id: string): Promise<{
|
|
153
|
-
acknowledged: boolean;
|
|
154
|
-
deletedCount: number;
|
|
155
|
-
}>;
|
|
156
|
-
}
|
package/dist/kokimoki-storage.js
DELETED
|
@@ -1,208 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Kokimoki Storage Service
|
|
3
|
-
*
|
|
4
|
-
* Provides file upload and management capabilities for game applications. Ideal for media files
|
|
5
|
-
* (images, videos, audio) and other data not suitable for real-time stores (JSON, text files).
|
|
6
|
-
*
|
|
7
|
-
* **Key Features:**
|
|
8
|
-
* - Upload files to cloud storage with CDN delivery
|
|
9
|
-
* - Tag-based organization and filtering
|
|
10
|
-
* - Query uploads by client, MIME type, or tags
|
|
11
|
-
* - Pagination support for large collections
|
|
12
|
-
* - Public CDN URLs for direct access
|
|
13
|
-
*
|
|
14
|
-
* **Common Use Cases:**
|
|
15
|
-
* - Player avatars and profile images
|
|
16
|
-
* - Game screenshots and replays
|
|
17
|
-
* - User-generated content
|
|
18
|
-
* - Asset uploads (levels, maps, custom skins)
|
|
19
|
-
* - JSON configuration files
|
|
20
|
-
*
|
|
21
|
-
* Access via `kmClient.storage`
|
|
22
|
-
*
|
|
23
|
-
* @example
|
|
24
|
-
* ```typescript
|
|
25
|
-
* // Upload an image
|
|
26
|
-
* const upload = await kmClient.storage.upload('avatar.jpg', imageBlob, ['profile']);
|
|
27
|
-
*
|
|
28
|
-
* // Query user's uploads
|
|
29
|
-
* const myUploads = await kmClient.storage.listUploads({
|
|
30
|
-
* clientId: kmClient.id
|
|
31
|
-
* });
|
|
32
|
-
*
|
|
33
|
-
* // Use in store
|
|
34
|
-
* await kmClient.transact([store], (state) => {
|
|
35
|
-
* state.playerAvatar = upload.url;
|
|
36
|
-
* });
|
|
37
|
-
* ```
|
|
38
|
-
*/
|
|
39
|
-
export class KokimokiStorage {
|
|
40
|
-
client;
|
|
41
|
-
constructor(client) {
|
|
42
|
-
this.client = client;
|
|
43
|
-
}
|
|
44
|
-
// Storage
|
|
45
|
-
async createUpload(name, blob, tags) {
|
|
46
|
-
const res = await fetch(`${this.client.apiUrl}/uploads`, {
|
|
47
|
-
method: "POST",
|
|
48
|
-
headers: this.client.apiHeaders,
|
|
49
|
-
body: JSON.stringify({
|
|
50
|
-
name,
|
|
51
|
-
size: blob.size,
|
|
52
|
-
mimeType: blob.type,
|
|
53
|
-
tags,
|
|
54
|
-
}),
|
|
55
|
-
});
|
|
56
|
-
return await res.json();
|
|
57
|
-
}
|
|
58
|
-
async uploadChunks(blob, chunkSize, signedUrls) {
|
|
59
|
-
return await Promise.all(signedUrls.map(async (url, index) => {
|
|
60
|
-
const start = index * chunkSize;
|
|
61
|
-
const end = Math.min(start + chunkSize, blob.size);
|
|
62
|
-
const chunk = blob.slice(start, end);
|
|
63
|
-
const res = await fetch(url, { method: "PUT", body: chunk });
|
|
64
|
-
return JSON.parse(res.headers.get("ETag") || '""');
|
|
65
|
-
}));
|
|
66
|
-
}
|
|
67
|
-
async completeUpload(id, etags) {
|
|
68
|
-
const res = await fetch(`${this.client.apiUrl}/uploads/${id}`, {
|
|
69
|
-
method: "PUT",
|
|
70
|
-
headers: this.client.apiHeaders,
|
|
71
|
-
body: JSON.stringify({ etags }),
|
|
72
|
-
});
|
|
73
|
-
return await res.json();
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Upload a file to cloud storage.
|
|
77
|
-
*
|
|
78
|
-
* Uploads a file (Blob) to Kokimoki storage and returns an Upload object with a public CDN URL.
|
|
79
|
-
* Files are automatically chunked for efficient upload. The returned URL can be used directly
|
|
80
|
-
* in your application (e.g., in img tags or store state).
|
|
81
|
-
*
|
|
82
|
-
* @param name The filename for the upload
|
|
83
|
-
* @param blob The Blob object containing the file data
|
|
84
|
-
* @param tags Optional array of tags for organizing and filtering uploads (default: [])
|
|
85
|
-
* @returns A promise resolving to the Upload object with CDN URL and metadata
|
|
86
|
-
*
|
|
87
|
-
* @example
|
|
88
|
-
* ```typescript
|
|
89
|
-
* // Upload image with tags
|
|
90
|
-
* const upload = await kmClient.storage.upload(
|
|
91
|
-
* 'avatar.jpg',
|
|
92
|
-
* imageBlob,
|
|
93
|
-
* ['profile', 'avatar']
|
|
94
|
-
* );
|
|
95
|
-
*
|
|
96
|
-
* // Use the CDN URL
|
|
97
|
-
* console.log(upload.url); // https://cdn.kokimoki.com/...
|
|
98
|
-
*
|
|
99
|
-
* // Store in game state
|
|
100
|
-
* await kmClient.transact([store], (state) => {
|
|
101
|
-
* state.players[kmClient.id].avatar = upload.url;
|
|
102
|
-
* });
|
|
103
|
-
* ```
|
|
104
|
-
*/
|
|
105
|
-
async upload(name, blob, tags = []) {
|
|
106
|
-
const { id, chunkSize, urls } = await this.createUpload(name, blob, tags);
|
|
107
|
-
const etags = await this.uploadChunks(blob, chunkSize, urls);
|
|
108
|
-
return await this.completeUpload(id, etags);
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* Update metadata for an existing upload.
|
|
112
|
-
*
|
|
113
|
-
* Allows you to replace the tags associated with an upload. Useful for reorganizing
|
|
114
|
-
* or recategorizing uploaded files.
|
|
115
|
-
*
|
|
116
|
-
* @param id The upload ID to update
|
|
117
|
-
* @param update Object containing the new tags array
|
|
118
|
-
* @returns A promise resolving to the updated Upload object
|
|
119
|
-
*
|
|
120
|
-
* @example
|
|
121
|
-
* ```typescript
|
|
122
|
-
* // Update tags
|
|
123
|
-
* const updated = await kmClient.storage.updateUpload(upload.id, {
|
|
124
|
-
* tags: ['archived', 'old-profile']
|
|
125
|
-
* });
|
|
126
|
-
* ```
|
|
127
|
-
*/
|
|
128
|
-
async updateUpload(id, update) {
|
|
129
|
-
const res = await fetch(`${this.client.apiUrl}/uploads/${id}`, {
|
|
130
|
-
method: "PUT",
|
|
131
|
-
headers: this.client.apiHeaders,
|
|
132
|
-
body: JSON.stringify(update),
|
|
133
|
-
});
|
|
134
|
-
return await res.json();
|
|
135
|
-
}
|
|
136
|
-
/**
|
|
137
|
-
* Query uploaded files with filtering and pagination.
|
|
138
|
-
*
|
|
139
|
-
* Retrieves a list of uploads matching the specified criteria. Supports filtering by
|
|
140
|
-
* client (uploader), MIME types, and tags. Use pagination for large collections.
|
|
141
|
-
*
|
|
142
|
-
* @param filter Optional filter criteria
|
|
143
|
-
* @param filter.clientId Filter by uploader's client ID
|
|
144
|
-
* @param filter.mimeTypes Filter by MIME types (e.g., ['image/jpeg', 'image/png'])
|
|
145
|
-
* @param filter.tags Filter by tags (all specified tags must match)
|
|
146
|
-
* @param skip Number of results to skip for pagination (default: 0)
|
|
147
|
-
* @param limit Maximum number of results to return (default: 100)
|
|
148
|
-
* @returns A promise resolving to paginated Upload results with total count
|
|
149
|
-
*
|
|
150
|
-
* @example
|
|
151
|
-
* ```typescript
|
|
152
|
-
* // Get current user's images
|
|
153
|
-
* const myImages = await kmClient.storage.listUploads({
|
|
154
|
-
* clientId: kmClient.id,
|
|
155
|
-
* mimeTypes: ['image/jpeg', 'image/png']
|
|
156
|
-
* });
|
|
157
|
-
*
|
|
158
|
-
* // Get all profile avatars
|
|
159
|
-
* const avatars = await kmClient.storage.listUploads({
|
|
160
|
-
* tags: ['profile', 'avatar']
|
|
161
|
-
* });
|
|
162
|
-
*
|
|
163
|
-
* // Pagination
|
|
164
|
-
* const page2 = await kmClient.storage.listUploads({}, 10, 10);
|
|
165
|
-
* ```
|
|
166
|
-
*/
|
|
167
|
-
async listUploads(filter = {}, skip = 0, limit = 100) {
|
|
168
|
-
const url = new URL("/uploads", this.client.apiUrl);
|
|
169
|
-
url.searchParams.set("skip", skip.toString());
|
|
170
|
-
url.searchParams.set("limit", limit.toString());
|
|
171
|
-
if (filter.clientId) {
|
|
172
|
-
url.searchParams.set("clientId", filter.clientId);
|
|
173
|
-
}
|
|
174
|
-
if (filter.mimeTypes) {
|
|
175
|
-
url.searchParams.set("mimeTypes", filter.mimeTypes.join());
|
|
176
|
-
}
|
|
177
|
-
if (filter.tags) {
|
|
178
|
-
url.searchParams.set("tags", filter.tags.join());
|
|
179
|
-
}
|
|
180
|
-
const res = await fetch(url.href, {
|
|
181
|
-
headers: this.client.apiHeaders,
|
|
182
|
-
});
|
|
183
|
-
return await res.json();
|
|
184
|
-
}
|
|
185
|
-
/**
|
|
186
|
-
* Permanently delete an uploaded file.
|
|
187
|
-
*
|
|
188
|
-
* Removes the file from cloud storage and the CDN. The URL will no longer be accessible.
|
|
189
|
-
* This operation cannot be undone.
|
|
190
|
-
*
|
|
191
|
-
* @param id The upload ID to delete
|
|
192
|
-
* @returns A promise resolving to deletion confirmation
|
|
193
|
-
*
|
|
194
|
-
* @example
|
|
195
|
-
* ```typescript
|
|
196
|
-
* // Delete an upload
|
|
197
|
-
* const result = await kmClient.storage.deleteUpload(upload.id);
|
|
198
|
-
* console.log(`Deleted: ${result.deletedCount} file(s)`);
|
|
199
|
-
* ```
|
|
200
|
-
*/
|
|
201
|
-
async deleteUpload(id) {
|
|
202
|
-
const res = await fetch(`${this.client.apiUrl}/uploads/${id}`, {
|
|
203
|
-
method: "DELETE",
|
|
204
|
-
headers: this.client.apiHeaders,
|
|
205
|
-
});
|
|
206
|
-
return await res.json();
|
|
207
|
-
}
|
|
208
|
-
}
|
package/dist/kokimoki-store.d.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import * as Y from "yjs";
|
|
2
|
-
import { Snapshot } from "valtio/vanilla";
|
|
3
|
-
import { RoomSubscriptionMode } from "./room-subscription-mode";
|
|
4
|
-
import type { KokimokiClient } from "./kokimoki-client";
|
|
5
|
-
export declare class KokimokiStore<T extends object> {
|
|
6
|
-
readonly roomName: string;
|
|
7
|
-
readonly defaultValue: T;
|
|
8
|
-
readonly mode: RoomSubscriptionMode;
|
|
9
|
-
readonly doc: Y.Doc;
|
|
10
|
-
readonly proxy: T;
|
|
11
|
-
readonly docRoot: Y.Map<unknown>;
|
|
12
|
-
readonly connections: {
|
|
13
|
-
connectionIds: Set<string>;
|
|
14
|
-
clientIds: Set<string>;
|
|
15
|
-
};
|
|
16
|
-
private _unsubscribeConnectionsHandler;
|
|
17
|
-
constructor(roomName: string, defaultValue: T, mode?: RoomSubscriptionMode);
|
|
18
|
-
get(): Snapshot<T>;
|
|
19
|
-
subscribe(set: (value: Snapshot<T>) => void): () => void;
|
|
20
|
-
onJoin(client: KokimokiClient<any>): Promise<void>;
|
|
21
|
-
onBeforeLeave(client: KokimokiClient): Promise<void>;
|
|
22
|
-
onLeave(client: KokimokiClient): Promise<void>;
|
|
23
|
-
}
|