@kokimoki/app 1.17.0 → 2.0.0

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.
@@ -0,0 +1,175 @@
1
+ import { KokimokiClient } from "./kokimoki-client";
2
+ import { Paginated } from "./types/common";
3
+ /**
4
+ * Kokimoki Leaderboard Service
5
+ *
6
+ * Provides efficient player ranking and score tracking with database indexes and optimized queries.
7
+ * Ideal for games with large numbers of players and competitive scoring.
8
+ *
9
+ * **Key Features:**
10
+ * - Efficient ranking with database indexes
11
+ * - Support for ascending (lowest-is-best) and descending (highest-is-best) sorting
12
+ * - Pagination for large leaderboards
13
+ * - Public and private metadata for entries
14
+ * - Insert (preserve all attempts) or upsert (keep latest only) modes
15
+ *
16
+ * **When to use Leaderboard API vs Global Store:**
17
+ *
18
+ * Use the **Leaderboard API** when:
19
+ * - You have a large number of entries (hundreds to thousands of players)
20
+ * - You need efficient ranking and sorting with database indexes
21
+ * - You want pagination and optimized queries for top scores
22
+ * - Memory and network efficiency are important
23
+ *
24
+ * Use a **Global Store** when:
25
+ * - You have a small number of players (typically under 100)
26
+ * - You need real-time updates and live leaderboard changes
27
+ * - You want to combine player scores with other game state
28
+ * - The leaderboard is temporary (session-based or reset frequently)
29
+ *
30
+ * Access via `kmClient.leaderboard`
31
+ *
32
+ * @example
33
+ * ```typescript
34
+ * // Submit a high score
35
+ * const { rank } = await kmClient.leaderboard.upsertEntry(
36
+ * 'high-scores',
37
+ * 'desc',
38
+ * 1500,
39
+ * { playerName: 'Alice' },
40
+ * {}
41
+ * );
42
+ *
43
+ * // Get top 10
44
+ * const { items } = await kmClient.leaderboard.listEntries('high-scores', 'desc', 0, 10);
45
+ *
46
+ * // Get player's best
47
+ * const best = await kmClient.leaderboard.getBestEntry('high-scores', 'desc');
48
+ * ```
49
+ */
50
+ export declare class KokimokiLeaderboard {
51
+ private readonly client;
52
+ constructor(client: KokimokiClient);
53
+ /**
54
+ * Add a new entry to a leaderboard.
55
+ *
56
+ * Creates a new entry each time it's called, preserving all attempts. Use this when you want
57
+ * to track every score submission (e.g., all game attempts).
58
+ *
59
+ * @param leaderboardName The name of the leaderboard to add the entry to
60
+ * @param sortDir Sort direction: "asc" for lowest-is-best (e.g., completion time),
61
+ * "desc" for highest-is-best (e.g., points)
62
+ * @param score The numeric score value
63
+ * @param metadata Public metadata visible to all players (e.g., player name, level)
64
+ * @param privateMetadata Private metadata only accessible via API calls (e.g., session ID)
65
+ * @returns A promise resolving to an object with the entry's rank
66
+ *
67
+ * @example
68
+ * ```typescript
69
+ * const { rank } = await kmClient.leaderboard.insertEntry(
70
+ * 'high-scores',
71
+ * 'desc',
72
+ * 1500,
73
+ * { playerName: 'Alice', level: 10 },
74
+ * { sessionId: 'abc123' }
75
+ * );
76
+ * console.log(`New rank: ${rank}`);
77
+ * ```
78
+ */
79
+ insertEntry<MetadataT, PrivateMetadataT>(leaderboardName: string, sortDir: "asc" | "desc", score: number, metadata: MetadataT, privateMetadata: PrivateMetadataT): Promise<{
80
+ rank: number;
81
+ }>;
82
+ /**
83
+ * Add or update the latest entry for the current client in a leaderboard.
84
+ *
85
+ * Replaces the previous entry if one exists for this client. Use this when you only want
86
+ * to keep the latest or best score per player (e.g., daily high score).
87
+ *
88
+ * @param leaderboardName The name of the leaderboard to upsert the entry in
89
+ * @param sortDir Sort direction: "asc" for lowest-is-best (e.g., completion time),
90
+ * "desc" for highest-is-best (e.g., points)
91
+ * @param score The numeric score value
92
+ * @param metadata Public metadata visible to all players (e.g., player name, completion time)
93
+ * @param privateMetadata Private metadata only accessible via API calls (e.g., device ID)
94
+ * @returns A promise resolving to an object with the entry's updated rank
95
+ *
96
+ * @example
97
+ * ```typescript
98
+ * const { rank } = await kmClient.leaderboard.upsertEntry(
99
+ * 'daily-scores',
100
+ * 'desc',
101
+ * 2000,
102
+ * { playerName: 'Bob', completionTime: 120 },
103
+ * { deviceId: 'xyz789' }
104
+ * );
105
+ * console.log(`Updated rank: ${rank}`);
106
+ * ```
107
+ */
108
+ upsertEntry<MetadataT, PrivateMetadataT>(leaderboardName: string, sortDir: "asc" | "desc", score: number, metadata: MetadataT, privateMetadata: PrivateMetadataT): Promise<{
109
+ rank: number;
110
+ }>;
111
+ /**
112
+ * List entries in a leaderboard with pagination.
113
+ *
114
+ * Retrieves a sorted list of leaderboard entries. Use skip and limit parameters for
115
+ * pagination (e.g., showing top 10, or implementing "load more" functionality).
116
+ *
117
+ * @param leaderboardName The name of the leaderboard to query
118
+ * @param sortDir Sort direction: "asc" for lowest-is-best (e.g., completion time),
119
+ * "desc" for highest-is-best (e.g., points)
120
+ * @param skip Number of entries to skip for pagination (default: 0)
121
+ * @param limit Maximum number of entries to return (default: 100)
122
+ * @returns A promise resolving to a paginated list of entries with rank, score, and metadata
123
+ *
124
+ * @example
125
+ * ```typescript
126
+ * // Get top 10 scores
127
+ * const { items, total } = await kmClient.leaderboard.listEntries(
128
+ * 'weekly-scores',
129
+ * 'desc',
130
+ * 0,
131
+ * 10
132
+ * );
133
+ *
134
+ * items.forEach(entry => {
135
+ * console.log(`Rank ${entry.rank}: ${entry.metadata.playerName} - ${entry.score}`);
136
+ * });
137
+ * ```
138
+ */
139
+ listEntries<MetadataT>(leaderboardName: string, sortDir: "asc" | "desc", skip?: number, limit?: number): Promise<Paginated<{
140
+ rank: number;
141
+ score: number;
142
+ metadata: MetadataT;
143
+ }>>;
144
+ /**
145
+ * Get the best entry for a specific client in a leaderboard.
146
+ *
147
+ * Retrieves the highest-ranked entry for a client based on the sort direction.
148
+ * Defaults to the current client if no clientId is provided.
149
+ *
150
+ * @param leaderboardName The name of the leaderboard to query
151
+ * @param sortDir Sort direction: "asc" for lowest-is-best (e.g., completion time),
152
+ * "desc" for highest-is-best (e.g., points)
153
+ * @param clientId The client ID to get the best entry for (optional, defaults to current client)
154
+ * @returns A promise resolving to the best entry with rank, score, and metadata
155
+ *
156
+ * @example
157
+ * ```typescript
158
+ * // Get current client's best entry
159
+ * const myBest = await kmClient.leaderboard.getBestEntry('all-time-high', 'desc');
160
+ * console.log(`My best: Rank ${myBest.rank}, Score ${myBest.score}`);
161
+ *
162
+ * // Get another player's best entry
163
+ * const otherBest = await kmClient.leaderboard.getBestEntry(
164
+ * 'all-time-high',
165
+ * 'desc',
166
+ * 'other-client-id'
167
+ * );
168
+ * ```
169
+ */
170
+ getBestEntry<MetadataT>(leaderboardName: string, sortDir: "asc" | "desc", clientId?: string): Promise<{
171
+ rank: number;
172
+ score: number;
173
+ metadata: MetadataT;
174
+ }>;
175
+ }
@@ -0,0 +1,203 @@
1
+ /**
2
+ * Kokimoki Leaderboard Service
3
+ *
4
+ * Provides efficient player ranking and score tracking with database indexes and optimized queries.
5
+ * Ideal for games with large numbers of players and competitive scoring.
6
+ *
7
+ * **Key Features:**
8
+ * - Efficient ranking with database indexes
9
+ * - Support for ascending (lowest-is-best) and descending (highest-is-best) sorting
10
+ * - Pagination for large leaderboards
11
+ * - Public and private metadata for entries
12
+ * - Insert (preserve all attempts) or upsert (keep latest only) modes
13
+ *
14
+ * **When to use Leaderboard API vs Global Store:**
15
+ *
16
+ * Use the **Leaderboard API** when:
17
+ * - You have a large number of entries (hundreds to thousands of players)
18
+ * - You need efficient ranking and sorting with database indexes
19
+ * - You want pagination and optimized queries for top scores
20
+ * - Memory and network efficiency are important
21
+ *
22
+ * Use a **Global Store** when:
23
+ * - You have a small number of players (typically under 100)
24
+ * - You need real-time updates and live leaderboard changes
25
+ * - You want to combine player scores with other game state
26
+ * - The leaderboard is temporary (session-based or reset frequently)
27
+ *
28
+ * Access via `kmClient.leaderboard`
29
+ *
30
+ * @example
31
+ * ```typescript
32
+ * // Submit a high score
33
+ * const { rank } = await kmClient.leaderboard.upsertEntry(
34
+ * 'high-scores',
35
+ * 'desc',
36
+ * 1500,
37
+ * { playerName: 'Alice' },
38
+ * {}
39
+ * );
40
+ *
41
+ * // Get top 10
42
+ * const { items } = await kmClient.leaderboard.listEntries('high-scores', 'desc', 0, 10);
43
+ *
44
+ * // Get player's best
45
+ * const best = await kmClient.leaderboard.getBestEntry('high-scores', 'desc');
46
+ * ```
47
+ */
48
+ export class KokimokiLeaderboard {
49
+ client;
50
+ constructor(client) {
51
+ this.client = client;
52
+ }
53
+ /**
54
+ * Add a new entry to a leaderboard.
55
+ *
56
+ * Creates a new entry each time it's called, preserving all attempts. Use this when you want
57
+ * to track every score submission (e.g., all game attempts).
58
+ *
59
+ * @param leaderboardName The name of the leaderboard to add the entry to
60
+ * @param sortDir Sort direction: "asc" for lowest-is-best (e.g., completion time),
61
+ * "desc" for highest-is-best (e.g., points)
62
+ * @param score The numeric score value
63
+ * @param metadata Public metadata visible to all players (e.g., player name, level)
64
+ * @param privateMetadata Private metadata only accessible via API calls (e.g., session ID)
65
+ * @returns A promise resolving to an object with the entry's rank
66
+ *
67
+ * @example
68
+ * ```typescript
69
+ * const { rank } = await kmClient.leaderboard.insertEntry(
70
+ * 'high-scores',
71
+ * 'desc',
72
+ * 1500,
73
+ * { playerName: 'Alice', level: 10 },
74
+ * { sessionId: 'abc123' }
75
+ * );
76
+ * console.log(`New rank: ${rank}`);
77
+ * ```
78
+ */
79
+ async insertEntry(leaderboardName, sortDir, score, metadata, privateMetadata) {
80
+ const res = await fetch(`${this.client.apiUrl}/leaderboard-entries`, {
81
+ method: "POST",
82
+ headers: this.client.apiHeaders,
83
+ body: JSON.stringify({
84
+ leaderboardName,
85
+ sortDir,
86
+ score,
87
+ metadata,
88
+ privateMetadata,
89
+ upsert: false,
90
+ }),
91
+ });
92
+ return await res.json();
93
+ }
94
+ /**
95
+ * Add or update the latest entry for the current client in a leaderboard.
96
+ *
97
+ * Replaces the previous entry if one exists for this client. Use this when you only want
98
+ * to keep the latest or best score per player (e.g., daily high score).
99
+ *
100
+ * @param leaderboardName The name of the leaderboard to upsert the entry in
101
+ * @param sortDir Sort direction: "asc" for lowest-is-best (e.g., completion time),
102
+ * "desc" for highest-is-best (e.g., points)
103
+ * @param score The numeric score value
104
+ * @param metadata Public metadata visible to all players (e.g., player name, completion time)
105
+ * @param privateMetadata Private metadata only accessible via API calls (e.g., device ID)
106
+ * @returns A promise resolving to an object with the entry's updated rank
107
+ *
108
+ * @example
109
+ * ```typescript
110
+ * const { rank } = await kmClient.leaderboard.upsertEntry(
111
+ * 'daily-scores',
112
+ * 'desc',
113
+ * 2000,
114
+ * { playerName: 'Bob', completionTime: 120 },
115
+ * { deviceId: 'xyz789' }
116
+ * );
117
+ * console.log(`Updated rank: ${rank}`);
118
+ * ```
119
+ */
120
+ async upsertEntry(leaderboardName, sortDir, score, metadata, privateMetadata) {
121
+ const res = await fetch(`${this.client.apiUrl}/leaderboard-entries`, {
122
+ method: "POST",
123
+ headers: this.client.apiHeaders,
124
+ body: JSON.stringify({
125
+ leaderboardName,
126
+ sortDir,
127
+ score,
128
+ metadata,
129
+ privateMetadata,
130
+ upsert: true,
131
+ }),
132
+ });
133
+ return await res.json();
134
+ }
135
+ /**
136
+ * List entries in a leaderboard with pagination.
137
+ *
138
+ * Retrieves a sorted list of leaderboard entries. Use skip and limit parameters for
139
+ * pagination (e.g., showing top 10, or implementing "load more" functionality).
140
+ *
141
+ * @param leaderboardName The name of the leaderboard to query
142
+ * @param sortDir Sort direction: "asc" for lowest-is-best (e.g., completion time),
143
+ * "desc" for highest-is-best (e.g., points)
144
+ * @param skip Number of entries to skip for pagination (default: 0)
145
+ * @param limit Maximum number of entries to return (default: 100)
146
+ * @returns A promise resolving to a paginated list of entries with rank, score, and metadata
147
+ *
148
+ * @example
149
+ * ```typescript
150
+ * // Get top 10 scores
151
+ * const { items, total } = await kmClient.leaderboard.listEntries(
152
+ * 'weekly-scores',
153
+ * 'desc',
154
+ * 0,
155
+ * 10
156
+ * );
157
+ *
158
+ * items.forEach(entry => {
159
+ * console.log(`Rank ${entry.rank}: ${entry.metadata.playerName} - ${entry.score}`);
160
+ * });
161
+ * ```
162
+ */
163
+ async listEntries(leaderboardName, sortDir, skip = 0, limit = 100) {
164
+ const encodedLeaderboardName = encodeURIComponent(leaderboardName);
165
+ const res = await fetch(`${this.client.apiUrl}/leaderboard-entries?leaderboardName=${encodedLeaderboardName}&sortDir=${sortDir}&skip=${skip}&limit=${limit}`, {
166
+ headers: this.client.apiHeaders,
167
+ });
168
+ return await res.json();
169
+ }
170
+ /**
171
+ * Get the best entry for a specific client in a leaderboard.
172
+ *
173
+ * Retrieves the highest-ranked entry for a client based on the sort direction.
174
+ * Defaults to the current client if no clientId is provided.
175
+ *
176
+ * @param leaderboardName The name of the leaderboard to query
177
+ * @param sortDir Sort direction: "asc" for lowest-is-best (e.g., completion time),
178
+ * "desc" for highest-is-best (e.g., points)
179
+ * @param clientId The client ID to get the best entry for (optional, defaults to current client)
180
+ * @returns A promise resolving to the best entry with rank, score, and metadata
181
+ *
182
+ * @example
183
+ * ```typescript
184
+ * // Get current client's best entry
185
+ * const myBest = await kmClient.leaderboard.getBestEntry('all-time-high', 'desc');
186
+ * console.log(`My best: Rank ${myBest.rank}, Score ${myBest.score}`);
187
+ *
188
+ * // Get another player's best entry
189
+ * const otherBest = await kmClient.leaderboard.getBestEntry(
190
+ * 'all-time-high',
191
+ * 'desc',
192
+ * 'other-client-id'
193
+ * );
194
+ * ```
195
+ */
196
+ async getBestEntry(leaderboardName, sortDir, clientId) {
197
+ const encodedLeaderboardName = encodeURIComponent(leaderboardName);
198
+ const res = await fetch(`${this.client.apiUrl}/leaderboard-entries/best?leaderboardName=${encodedLeaderboardName}&sortDir=${sortDir}&clientId=${clientId || this.client.id}`, {
199
+ headers: this.client.apiHeaders,
200
+ });
201
+ return await res.json();
202
+ }
203
+ }
@@ -0,0 +1,113 @@
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
+ }
@@ -0,0 +1,162 @@
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 = {}));