@kokimoki/app 1.7.0 → 1.7.2

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 CHANGED
@@ -1,7 +1,6 @@
1
1
  export * from "./types/common";
2
2
  export * from "./types/events";
3
3
  export * from "./types/upload";
4
- export * from "./fields";
5
4
  export * from "./kokimoki-client";
6
5
  export * from "./kokimoki-schema";
7
6
  export * from "./kokimoki-store";
package/dist/index.js CHANGED
@@ -1,7 +1,6 @@
1
1
  export * from "./types/common";
2
2
  export * from "./types/events";
3
3
  export * from "./types/upload";
4
- export * from "./fields";
5
4
  export * from "./kokimoki-client";
6
5
  export * from "./kokimoki-schema";
7
6
  export * from "./kokimoki-store";
@@ -93,7 +93,7 @@ export declare class KokimokiClient<ClientContextT = any> extends KokimokiClient
93
93
  * @param metadata
94
94
  * @returns
95
95
  */
96
- insertLeaderboardEntry<MetadataT, PrivateMetadataT>(leaderboardName: string, score: number, metadata: MetadataT, privateMetadata: PrivateMetadataT): Promise<{
96
+ insertLeaderboardEntry<MetadataT, PrivateMetadataT>(leaderboardName: string, sortMethod: "asc" | "desc", score: number, metadata: MetadataT, privateMetadata: PrivateMetadataT): Promise<{
97
97
  rank: number;
98
98
  }>;
99
99
  /**
@@ -104,7 +104,7 @@ export declare class KokimokiClient<ClientContextT = any> extends KokimokiClient
104
104
  * @param privateMetadata Can only be read using the leaderboard API
105
105
  * @returns
106
106
  */
107
- upsertLeaderboardEntry<MetadataT, PrivateMetadataT>(leaderboardName: string, score: number, metadata: MetadataT, privateMetadata: PrivateMetadataT): Promise<{
107
+ upsertLeaderboardEntry<MetadataT, PrivateMetadataT>(leaderboardName: string, sortMethod: "asc" | "desc", score: number, metadata: MetadataT, privateMetadata: PrivateMetadataT): Promise<{
108
108
  rank: number;
109
109
  }>;
110
110
  /**
@@ -114,7 +114,7 @@ export declare class KokimokiClient<ClientContextT = any> extends KokimokiClient
114
114
  * @param limit
115
115
  * @returns
116
116
  */
117
- listLeaderboardEntries<MetadataT>(leaderboardName: string, skip?: number, limit?: number): Promise<Paginated<{
117
+ listLeaderboardEntries<MetadataT>(leaderboardName: string, sortMethod: "asc" | "desc", skip?: number, limit?: number): Promise<Paginated<{
118
118
  score: number;
119
119
  metadata: MetadataT;
120
120
  }>>;
@@ -615,12 +615,13 @@ export class KokimokiClient extends EventEmitter {
615
615
  * @param metadata
616
616
  * @returns
617
617
  */
618
- async insertLeaderboardEntry(leaderboardName, score, metadata, privateMetadata) {
618
+ async insertLeaderboardEntry(leaderboardName, sortMethod, score, metadata, privateMetadata) {
619
619
  const res = await fetch(`${this._apiUrl}/leaderboard-entries`, {
620
620
  method: "POST",
621
621
  headers: this.apiHeaders,
622
622
  body: JSON.stringify({
623
623
  leaderboardName,
624
+ sortMethod,
624
625
  score,
625
626
  metadata,
626
627
  privateMetadata,
@@ -637,12 +638,13 @@ export class KokimokiClient extends EventEmitter {
637
638
  * @param privateMetadata Can only be read using the leaderboard API
638
639
  * @returns
639
640
  */
640
- async upsertLeaderboardEntry(leaderboardName, score, metadata, privateMetadata) {
641
+ async upsertLeaderboardEntry(leaderboardName, sortMethod, score, metadata, privateMetadata) {
641
642
  const res = await fetch(`${this._apiUrl}/leaderboard-entries`, {
642
643
  method: "POST",
643
644
  headers: this.apiHeaders,
644
645
  body: JSON.stringify({
645
646
  leaderboardName,
647
+ sortMethod,
646
648
  score,
647
649
  metadata,
648
650
  privateMetadata,
@@ -658,8 +660,8 @@ export class KokimokiClient extends EventEmitter {
658
660
  * @param limit
659
661
  * @returns
660
662
  */
661
- async listLeaderboardEntries(leaderboardName, skip = 0, limit = 100) {
662
- const res = await fetch(`${this._apiUrl}/leaderboard-entries?leaderboardName=${leaderboardName}&skip=${skip}&limit=${limit}`);
663
+ async listLeaderboardEntries(leaderboardName, sortMethod, skip = 0, limit = 100) {
664
+ const res = await fetch(`${this._apiUrl}/leaderboard-entries?leaderboardName=${leaderboardName}&sortMethod=${sortMethod}&skip=${skip}&limit=${limit}`);
663
665
  return await res.json();
664
666
  }
665
667
  }
@@ -24,102 +24,6 @@ interface Upload {
24
24
  tags: string[];
25
25
  }
26
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
27
  declare namespace KokimokiSchema {
124
28
  abstract class Generic<T> {
125
29
  abstract get defaultValue(): T;
@@ -412,7 +316,7 @@ declare class KokimokiClient<ClientContextT = any> extends KokimokiClient_base {
412
316
  * @param metadata
413
317
  * @returns
414
318
  */
415
- insertLeaderboardEntry<MetadataT, PrivateMetadataT>(leaderboardName: string, score: number, metadata: MetadataT, privateMetadata: PrivateMetadataT): Promise<{
319
+ insertLeaderboardEntry<MetadataT, PrivateMetadataT>(leaderboardName: string, sortMethod: "asc" | "desc", score: number, metadata: MetadataT, privateMetadata: PrivateMetadataT): Promise<{
416
320
  rank: number;
417
321
  }>;
418
322
  /**
@@ -423,7 +327,7 @@ declare class KokimokiClient<ClientContextT = any> extends KokimokiClient_base {
423
327
  * @param privateMetadata Can only be read using the leaderboard API
424
328
  * @returns
425
329
  */
426
- upsertLeaderboardEntry<MetadataT, PrivateMetadataT>(leaderboardName: string, score: number, metadata: MetadataT, privateMetadata: PrivateMetadataT): Promise<{
330
+ upsertLeaderboardEntry<MetadataT, PrivateMetadataT>(leaderboardName: string, sortMethod: "asc" | "desc", score: number, metadata: MetadataT, privateMetadata: PrivateMetadataT): Promise<{
427
331
  rank: number;
428
332
  }>;
429
333
  /**
@@ -433,7 +337,7 @@ declare class KokimokiClient<ClientContextT = any> extends KokimokiClient_base {
433
337
  * @param limit
434
338
  * @returns
435
339
  */
436
- listLeaderboardEntries<MetadataT>(leaderboardName: string, skip?: number, limit?: number): Promise<Paginated<{
340
+ listLeaderboardEntries<MetadataT>(leaderboardName: string, sortMethod: "asc" | "desc", skip?: number, limit?: number): Promise<Paginated<{
437
341
  score: number;
438
342
  metadata: MetadataT;
439
343
  }>>;
@@ -453,4 +357,4 @@ declare class RoomSubscription {
453
357
  close(): void;
454
358
  }
455
359
 
456
- export { BooleanField, ConstField, EnumField, Field, type FieldOptions, FloatField, Form, FormArray, FormGroup, ImageField, IntegerField, KokimokiAwareness, KokimokiClient, type KokimokiClientEvents, KokimokiQueue, KokimokiSchema, KokimokiStore, type Paginated, RoomSubscription, RoomSubscriptionMode, TextField, type Upload };
360
+ export { KokimokiAwareness, KokimokiClient, type KokimokiClientEvents, KokimokiQueue, KokimokiSchema, KokimokiStore, type Paginated, RoomSubscription, RoomSubscriptionMode, type Upload };
@@ -1,159 +1,6 @@
1
1
  import require$$1 from 'path';
2
2
  import require$$2 from 'fs';
3
3
 
4
- const defaultFieldOptions = {};
5
- class Field {
6
- options;
7
- constructor(options) {
8
- this.options = options;
9
- }
10
- }
11
- class BooleanField extends Field {
12
- value;
13
- constructor(value, options = defaultFieldOptions) {
14
- super(options);
15
- this.value = value;
16
- }
17
- get schema() {
18
- return {
19
- type: "boolean",
20
- default: this.value,
21
- };
22
- }
23
- }
24
- class ConstField extends Field {
25
- value;
26
- constructor(value, options = defaultFieldOptions) {
27
- super(options);
28
- this.value = value;
29
- }
30
- get schema() {
31
- return {
32
- const: this.value,
33
- };
34
- }
35
- }
36
- class ImageField extends Field {
37
- value;
38
- constructor(value, options = defaultFieldOptions) {
39
- super(options);
40
- this.value = value;
41
- }
42
- get schema() {
43
- return {
44
- type: "string",
45
- default: this.value,
46
- };
47
- }
48
- }
49
- class TextField extends Field {
50
- value;
51
- constructor(value, options = defaultFieldOptions) {
52
- super(options);
53
- this.value = value;
54
- }
55
- get schema() {
56
- return {
57
- type: "string",
58
- default: this.value,
59
- };
60
- }
61
- }
62
- class EnumField extends Field {
63
- enumValues;
64
- value;
65
- constructor(enumValues, value, options = defaultFieldOptions) {
66
- super(options);
67
- this.enumValues = enumValues;
68
- this.value = value;
69
- }
70
- get schema() {
71
- return {
72
- enum: Object.keys(this.enumValues),
73
- };
74
- }
75
- }
76
- class IntegerField extends Field {
77
- value;
78
- constructor(value, options = defaultFieldOptions) {
79
- super(options);
80
- this.value = value;
81
- }
82
- get schema() {
83
- return {
84
- type: "integer",
85
- default: this.value,
86
- };
87
- }
88
- }
89
- class FloatField extends Field {
90
- value;
91
- constructor(value, options = defaultFieldOptions) {
92
- super(options);
93
- this.value = value;
94
- }
95
- get schema() {
96
- return {
97
- type: "number",
98
- default: this.value,
99
- };
100
- }
101
- }
102
- class FormGroup extends Field {
103
- requiredFields;
104
- optionalFields;
105
- constructor(requiredFields, optionalFields = {}, options = defaultFieldOptions) {
106
- super(options);
107
- this.requiredFields = requiredFields;
108
- this.optionalFields = optionalFields;
109
- }
110
- get value() {
111
- const value = Object.entries(this.requiredFields).reduce((acc, [key, field]) => {
112
- acc[key] = field.value;
113
- return acc;
114
- }, {});
115
- Object.entries(this.optionalFields).forEach(([key, field]) => {
116
- if (field.value !== undefined) {
117
- value[key] = field.value;
118
- }
119
- });
120
- return value;
121
- }
122
- get schema() {
123
- const properties = {};
124
- Object.entries(this.requiredFields).forEach(([key, field]) => {
125
- properties[key] = field.schema;
126
- });
127
- Object.entries(this.optionalFields).forEach(([key, field]) => {
128
- properties[key] = field.schema;
129
- });
130
- return {
131
- type: "object",
132
- properties,
133
- required: Object.keys(this.requiredFields),
134
- };
135
- }
136
- }
137
- class FormArray extends Field {
138
- factory;
139
- value;
140
- constructor(factory, value, options = defaultFieldOptions) {
141
- super(options);
142
- this.factory = factory;
143
- this.value = value;
144
- }
145
- get schema() {
146
- const field = this.factory();
147
- return {
148
- type: "array",
149
- items: field.schema,
150
- default: this.value,
151
- };
152
- }
153
- }
154
- class Form extends FormGroup {
155
- }
156
-
157
4
  var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
158
5
 
159
6
  function getDefaultExportFromCjs (x) {
@@ -639,7 +486,7 @@ function eventTargetAgnosticAddListener(emitter, name, listener, flags) {
639
486
  var eventsExports = events.exports;
640
487
  var EventEmitter$1 = /*@__PURE__*/getDefaultExportFromCjs(eventsExports);
641
488
 
642
- const KOKIMOKI_APP_VERSION = "1.7.0";
489
+ const KOKIMOKI_APP_VERSION = "1.7.2";
643
490
 
644
491
  /**
645
492
  * Utility module to work with key-value stores.
@@ -15398,12 +15245,13 @@ class KokimokiClient extends EventEmitter$1 {
15398
15245
  * @param metadata
15399
15246
  * @returns
15400
15247
  */
15401
- async insertLeaderboardEntry(leaderboardName, score, metadata, privateMetadata) {
15248
+ async insertLeaderboardEntry(leaderboardName, sortMethod, score, metadata, privateMetadata) {
15402
15249
  const res = await fetch(`${this._apiUrl}/leaderboard-entries`, {
15403
15250
  method: "POST",
15404
15251
  headers: this.apiHeaders,
15405
15252
  body: JSON.stringify({
15406
15253
  leaderboardName,
15254
+ sortMethod,
15407
15255
  score,
15408
15256
  metadata,
15409
15257
  privateMetadata,
@@ -15420,12 +15268,13 @@ class KokimokiClient extends EventEmitter$1 {
15420
15268
  * @param privateMetadata Can only be read using the leaderboard API
15421
15269
  * @returns
15422
15270
  */
15423
- async upsertLeaderboardEntry(leaderboardName, score, metadata, privateMetadata) {
15271
+ async upsertLeaderboardEntry(leaderboardName, sortMethod, score, metadata, privateMetadata) {
15424
15272
  const res = await fetch(`${this._apiUrl}/leaderboard-entries`, {
15425
15273
  method: "POST",
15426
15274
  headers: this.apiHeaders,
15427
15275
  body: JSON.stringify({
15428
15276
  leaderboardName,
15277
+ sortMethod,
15429
15278
  score,
15430
15279
  metadata,
15431
15280
  privateMetadata,
@@ -15441,11 +15290,11 @@ class KokimokiClient extends EventEmitter$1 {
15441
15290
  * @param limit
15442
15291
  * @returns
15443
15292
  */
15444
- async listLeaderboardEntries(leaderboardName, skip = 0, limit = 100) {
15445
- const res = await fetch(`${this._apiUrl}/leaderboard-entries?leaderboardName=${leaderboardName}&skip=${skip}&limit=${limit}`);
15293
+ async listLeaderboardEntries(leaderboardName, sortMethod, skip = 0, limit = 100) {
15294
+ const res = await fetch(`${this._apiUrl}/leaderboard-entries?leaderboardName=${leaderboardName}&sortMethod=${sortMethod}&skip=${skip}&limit=${limit}`);
15446
15295
  return await res.json();
15447
15296
  }
15448
15297
  }
15449
15298
 
15450
- export { BooleanField, ConstField, EnumField, Field, FloatField, Form, FormArray, FormGroup, ImageField, IntegerField, KokimokiAwareness, KokimokiClient, KokimokiQueue, KokimokiSchema, KokimokiStore, RoomSubscription, RoomSubscriptionMode, TextField };
15299
+ export { KokimokiAwareness, KokimokiClient, KokimokiQueue, KokimokiSchema, KokimokiStore, RoomSubscription, RoomSubscriptionMode };
15451
15300
  //# sourceMappingURL=kokimoki.min.js.map