@kokimoki/app 1.6.0 → 1.7.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.
@@ -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;
@@ -405,6 +309,38 @@ declare class KokimokiClient<ClientContextT = any> extends KokimokiClient_base {
405
309
  queue<T extends KokimokiSchema.Generic<unknown>>(name: string, schema: T, mode: RoomSubscriptionMode, autoJoin?: boolean): KokimokiQueue<T>;
406
310
  awareness<T extends KokimokiSchema.Generic<unknown>>(name: string, dataSchema: T, initialData?: T["defaultValue"], autoJoin?: boolean): KokimokiAwareness<T>;
407
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>;
312
+ /**
313
+ * Add a new entry to a leaderboard
314
+ * @param leaderboardName
315
+ * @param score
316
+ * @param metadata
317
+ * @returns
318
+ */
319
+ insertLeaderboardEntry<MetadataT, PrivateMetadataT>(leaderboardName: string, score: number, metadata: MetadataT, privateMetadata: PrivateMetadataT): Promise<{
320
+ rank: number;
321
+ }>;
322
+ /**
323
+ * Add or update latest entry to a leaderboard
324
+ * @param leaderboardName
325
+ * @param score
326
+ * @param metadata
327
+ * @param privateMetadata Can only be read using the leaderboard API
328
+ * @returns
329
+ */
330
+ upsertLeaderboardEntry<MetadataT, PrivateMetadataT>(leaderboardName: string, score: number, metadata: MetadataT, privateMetadata: PrivateMetadataT): Promise<{
331
+ rank: number;
332
+ }>;
333
+ /**
334
+ * List entries in a leaderboard
335
+ * @param leaderboardName
336
+ * @param skip
337
+ * @param limit
338
+ * @returns
339
+ */
340
+ listLeaderboardEntries<MetadataT>(leaderboardName: string, skip?: number, limit?: number): Promise<Paginated<{
341
+ score: number;
342
+ metadata: MetadataT;
343
+ }>>;
408
344
  }
409
345
 
410
346
  declare class RoomSubscription {
@@ -421,4 +357,4 @@ declare class RoomSubscription {
421
357
  close(): void;
422
358
  }
423
359
 
424
- 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.6.0";
489
+ const KOKIMOKI_APP_VERSION = "1.7.1";
643
490
 
644
491
  /**
645
492
  * Utility module to work with key-value stores.
@@ -15391,7 +15238,61 @@ class KokimokiClient extends EventEmitter$1 {
15391
15238
  reqRes(serviceName, reqSchema, resSchema, handleRequest) {
15392
15239
  return new KokimokiReqRes(this, serviceName, reqSchema, resSchema, handleRequest);
15393
15240
  }
15241
+ /**
15242
+ * Add a new entry to a leaderboard
15243
+ * @param leaderboardName
15244
+ * @param score
15245
+ * @param metadata
15246
+ * @returns
15247
+ */
15248
+ async insertLeaderboardEntry(leaderboardName, score, metadata, privateMetadata) {
15249
+ const res = await fetch(`${this._apiUrl}/leaderboard-entries`, {
15250
+ method: "POST",
15251
+ headers: this.apiHeaders,
15252
+ body: JSON.stringify({
15253
+ leaderboardName,
15254
+ score,
15255
+ metadata,
15256
+ privateMetadata,
15257
+ upsert: false,
15258
+ }),
15259
+ });
15260
+ return await res.json();
15261
+ }
15262
+ /**
15263
+ * Add or update latest entry to a leaderboard
15264
+ * @param leaderboardName
15265
+ * @param score
15266
+ * @param metadata
15267
+ * @param privateMetadata Can only be read using the leaderboard API
15268
+ * @returns
15269
+ */
15270
+ async upsertLeaderboardEntry(leaderboardName, score, metadata, privateMetadata) {
15271
+ const res = await fetch(`${this._apiUrl}/leaderboard-entries`, {
15272
+ method: "POST",
15273
+ headers: this.apiHeaders,
15274
+ body: JSON.stringify({
15275
+ leaderboardName,
15276
+ score,
15277
+ metadata,
15278
+ privateMetadata,
15279
+ upsert: true,
15280
+ }),
15281
+ });
15282
+ return await res.json();
15283
+ }
15284
+ /**
15285
+ * List entries in a leaderboard
15286
+ * @param leaderboardName
15287
+ * @param skip
15288
+ * @param limit
15289
+ * @returns
15290
+ */
15291
+ async listLeaderboardEntries(leaderboardName, skip = 0, limit = 100) {
15292
+ const res = await fetch(`${this._apiUrl}/leaderboard-entries?leaderboardName=${leaderboardName}&skip=${skip}&limit=${limit}`);
15293
+ return await res.json();
15294
+ }
15394
15295
  }
15395
15296
 
15396
- export { BooleanField, ConstField, EnumField, Field, FloatField, Form, FormArray, FormGroup, ImageField, IntegerField, KokimokiAwareness, KokimokiClient, KokimokiQueue, KokimokiSchema, KokimokiStore, RoomSubscription, RoomSubscriptionMode, TextField };
15297
+ export { KokimokiAwareness, KokimokiClient, KokimokiQueue, KokimokiSchema, KokimokiStore, RoomSubscription, RoomSubscriptionMode };
15397
15298
  //# sourceMappingURL=kokimoki.min.js.map