@rbxts/scribe 2.5.0 → 2.6.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.
- package/LICENSE +21 -21
- package/README.md +105 -100
- package/Scribe-source-map.json +1 -1
- package/licenses/ProfileStore-Apache-2.0.txt +201 -201
- package/package.json +1 -1
- package/src/Client/init.luau +9 -12
- package/src/Internal/Datatypes.luau +12 -6
- package/src/Internal/Derived.luau +37 -7
- package/src/Internal/ExchangeLeg.luau +7 -7
- package/src/Internal/Failure.luau +41 -5
- package/src/Internal/Node.luau +264 -62
- package/src/Internal/Signal.luau +21 -0
- package/src/Internal/Store/ProfileStore.luau +21 -0
- package/src/Internal/Template.luau +96 -8
- package/src/Internal/Version.luau +1 -1
- package/src/Server/Commands.luau +34 -12
- package/src/Server/DebugHook.luau +1 -1
- package/src/Server/Leaderboards.luau +3 -3
- package/src/Server/Monetization.luau +98 -40
- package/src/Server/Persistence.luau +220 -103
- package/src/Server/Replication.luau +232 -23
- package/src/Server/Timed.luau +2 -2
- package/src/Types.luau +31 -2
- package/src/init.luau +600 -160
- package/types/api.d.ts +334 -252
- package/types/common.d.ts +377 -355
- package/types/index.d.ts +281 -226
- package/types/schema.d.ts +340 -276
package/types/schema.d.ts
CHANGED
|
@@ -1,276 +1,340 @@
|
|
|
1
|
-
/** Schema declarations have no JavaScript runtime; Scribe constructs the markers in Luau. */
|
|
2
|
-
declare const declaration: unique symbol;
|
|
3
|
-
export interface Declaration<K extends string, T> {
|
|
4
|
-
readonly [declaration]: readonly [K, T];
|
|
5
|
-
}
|
|
6
|
-
export type ServerOnly<T> = Declaration<"ServerOnly", T>;
|
|
7
|
-
export type Shared<T> = Declaration<"Shared", T>;
|
|
8
|
-
export type Session<T> = Declaration<"Session", T>;
|
|
9
|
-
export type Timed<T> = Declaration<"Timed", T>;
|
|
10
|
-
export type Derived<T> = Declaration<"Derived", T>;
|
|
11
|
-
export type Optional<T> = Declaration<"Optional", T>;
|
|
12
|
-
export type ArrayOf<T> = Declaration<"ArrayOf", T>;
|
|
13
|
-
export type DictOf<T> = Declaration<"DictOf", T>;
|
|
14
|
-
export type MapOf<K extends "integer" | "string", T> = Declaration<"MapOf", readonly [K, T]>;
|
|
15
|
-
export type SetOf<T> = Declaration<"SetOf", T>;
|
|
16
|
-
export type Flags<K extends string = string> = Declaration<"Flags", K>;
|
|
17
|
-
export type EnumValue<K extends string> = Declaration<"Enum", K>;
|
|
18
|
-
export type BigSchema = Declaration<"Big", BigValue>;
|
|
19
|
-
export type Disconnect = (this: void) => void;
|
|
20
|
-
/** Numeric strings are validated at runtime and limited to 256 bytes before whitespace removal. */
|
|
21
|
-
export type BigOperand = BigValue | number | string;
|
|
22
|
-
|
|
23
|
-
/** Immutable mantissa/exponent value. These are genuine Luau self methods. */
|
|
24
|
-
export interface BigValue {
|
|
25
|
-
|
|
26
|
-
readonly
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
:
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
:
|
|
79
|
-
:
|
|
80
|
-
:
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
:
|
|
86
|
-
:
|
|
87
|
-
:
|
|
88
|
-
:
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
:
|
|
92
|
-
:
|
|
93
|
-
: T extends
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
:
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
: K extends "
|
|
104
|
-
:
|
|
105
|
-
:
|
|
106
|
-
: T extends
|
|
107
|
-
: T extends
|
|
108
|
-
: T extends
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
:
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
type
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
:
|
|
119
|
-
:
|
|
120
|
-
:
|
|
121
|
-
: T extends
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
: T
|
|
125
|
-
type
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
readonly
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
interface
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
readonly
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
:
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
readonly
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
readonly
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
type
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
readonly
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
readonly
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
readonly
|
|
195
|
-
|
|
196
|
-
readonly
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
readonly
|
|
203
|
-
|
|
204
|
-
readonly
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
readonly
|
|
223
|
-
|
|
224
|
-
readonly
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
readonly
|
|
234
|
-
|
|
235
|
-
readonly
|
|
236
|
-
} &
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
:
|
|
241
|
-
|
|
242
|
-
:
|
|
243
|
-
|
|
244
|
-
:
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
/**
|
|
252
|
-
readonly
|
|
253
|
-
} & WritableOnly<T, ReadOnly, {
|
|
254
|
-
|
|
255
|
-
readonly
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
:
|
|
271
|
-
|
|
272
|
-
:
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
1
|
+
/** Schema declarations have no JavaScript runtime; Scribe constructs the markers in Luau. */
|
|
2
|
+
declare const declaration: unique symbol;
|
|
3
|
+
export interface Declaration<K extends string, T> {
|
|
4
|
+
readonly [declaration]: readonly [K, T];
|
|
5
|
+
}
|
|
6
|
+
export type ServerOnly<T> = Declaration<"ServerOnly", T>;
|
|
7
|
+
export type Shared<T> = Declaration<"Shared", T>;
|
|
8
|
+
export type Session<T> = Declaration<"Session", T>;
|
|
9
|
+
export type Timed<T> = Declaration<"Timed", T>;
|
|
10
|
+
export type Derived<T> = Declaration<"Derived", T>;
|
|
11
|
+
export type Optional<T> = Declaration<"Optional", T>;
|
|
12
|
+
export type ArrayOf<T> = Declaration<"ArrayOf", T>;
|
|
13
|
+
export type DictOf<T> = Declaration<"DictOf", T>;
|
|
14
|
+
export type MapOf<K extends "integer" | "string", T> = Declaration<"MapOf", readonly [K, T]>;
|
|
15
|
+
export type SetOf<T> = Declaration<"SetOf", T>;
|
|
16
|
+
export type Flags<K extends string = string> = Declaration<"Flags", K>;
|
|
17
|
+
export type EnumValue<K extends string> = Declaration<"Enum", K>;
|
|
18
|
+
export type BigSchema = Declaration<"Big", BigValue>;
|
|
19
|
+
export type Disconnect = (this: void) => void;
|
|
20
|
+
/** Numeric strings are validated at runtime and limited to 256 bytes before whitespace removal. */
|
|
21
|
+
export type BigOperand = BigValue | number | string;
|
|
22
|
+
|
|
23
|
+
/** Immutable mantissa/exponent value. These are genuine Luau self methods. */
|
|
24
|
+
export interface BigValue {
|
|
25
|
+
/** The normalized mantissa, including its sign. */
|
|
26
|
+
readonly M: number;
|
|
27
|
+
/** The base-10 exponent. */
|
|
28
|
+
readonly E: number;
|
|
29
|
+
/** Returns the sum as a new Big value. */
|
|
30
|
+
Add(other: BigOperand): BigValue;
|
|
31
|
+
/** Returns the difference as a new Big value. */
|
|
32
|
+
Subtract(other: BigOperand): BigValue;
|
|
33
|
+
/** Returns the product as a new Big value. */
|
|
34
|
+
Multiply(other: BigOperand): BigValue;
|
|
35
|
+
/** Returns the quotient as a new Big value; rejects division by zero. */
|
|
36
|
+
Divide(other: BigOperand): BigValue;
|
|
37
|
+
/** Returns a new Big value with the opposite sign. */
|
|
38
|
+
Negate(): BigValue;
|
|
39
|
+
/** Returns -1, 0 or 1 when smaller, equal or larger than the other value. */
|
|
40
|
+
Compare(other: BigOperand): number;
|
|
41
|
+
/** Checks whether the numeric values are equal. */
|
|
42
|
+
Equals(other: BigOperand): boolean;
|
|
43
|
+
/** Returns a new power; the exponent must be an integer from 0 to 2^53. */
|
|
44
|
+
Pow(exponent: number): BigValue;
|
|
45
|
+
/** Returns the base-10 logarithm as a plain number. */
|
|
46
|
+
Log10(): number;
|
|
47
|
+
/** Formats a compact label, using two decimal places by default. */
|
|
48
|
+
Short(decimals?: number): string;
|
|
49
|
+
/** Converts to a plain number, which can lose precision or overflow. */
|
|
50
|
+
ToNumber(): number;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export type Datatype = Vector3 | Vector2 | Vector3int16 | Vector2int16 | CFrame | Color3 |
|
|
54
|
+
BrickColor | UDim | UDim2 | Rect | NumberRange | NumberSequence | ColorSequence |
|
|
55
|
+
DateTime | EnumItem | Font | PhysicalProperties;
|
|
56
|
+
export type AtomicValue = Datatype | buffer | BigValue;
|
|
57
|
+
type Widen<T> = T extends number ? number : T extends boolean ? boolean : T extends string ? string : T;
|
|
58
|
+
type KeyOfMap<K> = K extends "integer" ? number : string;
|
|
59
|
+
type OptionalField<T> = undefined extends T ? true : T extends Declaration<infer K, infer V>
|
|
60
|
+
? K extends "Optional" ? true : K extends "ServerOnly" | "Shared" | "Session" ? OptionalField<V> : false
|
|
61
|
+
: false;
|
|
62
|
+
type Simplify<T> = { [K in keyof T]: T[K] };
|
|
63
|
+
type ValueRecord<T> = Simplify<{
|
|
64
|
+
-readonly [K in keyof T as OptionalField<T[K]> extends true ? never : K]: ValueOf<T[K]>;
|
|
65
|
+
} & {
|
|
66
|
+
-readonly [K in keyof T as OptionalField<T[K]> extends true ? K : never]?: ValueOf<T[K]>;
|
|
67
|
+
}>;
|
|
68
|
+
type InputRecord<T> = Simplify<{
|
|
69
|
+
readonly [K in keyof T as OptionalField<T[K]> extends true ? never : K]: InputOf<T[K]>;
|
|
70
|
+
} & {
|
|
71
|
+
readonly [K in keyof T as OptionalField<T[K]> extends true ? K : never]?: InputOf<T[K]>;
|
|
72
|
+
}>;
|
|
73
|
+
|
|
74
|
+
/** Plain, detached value shape; marker wrappers never appear in saved/read values. */
|
|
75
|
+
export type ValueOf<T> = T extends Declaration<infer K, infer V>
|
|
76
|
+
? K extends "Big" ? BigValue
|
|
77
|
+
: K extends "Enum" ? V
|
|
78
|
+
: K extends "Optional" ? ValueOf<V> | undefined
|
|
79
|
+
: K extends "Flags" ? Extract<V, string>[]
|
|
80
|
+
: K extends "ArrayOf" | "SetOf" ? ValueOf<V>[]
|
|
81
|
+
: K extends "DictOf" ? { [key: string]: ValueOf<V> | undefined }
|
|
82
|
+
: K extends "MapOf" ? V extends readonly [infer MK, infer MV] ? Map<KeyOfMap<MK>, ValueOf<MV>> : never
|
|
83
|
+
: ValueOf<V>
|
|
84
|
+
: T extends AtomicValue ? T
|
|
85
|
+
: T extends ReadonlyArray<infer E> ? ValueOf<E>[]
|
|
86
|
+
: T extends ReadonlyMap<infer K, infer V> ? Map<K, ValueOf<V>>
|
|
87
|
+
: T extends object ? ValueRecord<T>
|
|
88
|
+
: Widen<T>;
|
|
89
|
+
|
|
90
|
+
export type DeepReadonly<T> = T extends AtomicValue ? T
|
|
91
|
+
: T extends ReadonlyArray<infer V> ? ReadonlyArray<DeepReadonly<V>>
|
|
92
|
+
: T extends ReadonlyMap<infer K, infer V> ? ReadonlyMap<K, DeepReadonly<V>>
|
|
93
|
+
: T extends object ? { readonly [K in keyof T]: DeepReadonly<T[K]> } : T;
|
|
94
|
+
|
|
95
|
+
/** Accepted writes. Big values additionally accept numbers and decimal strings. */
|
|
96
|
+
export type InputOf<T> = T extends Declaration<infer K, infer V>
|
|
97
|
+
? K extends "Big" ? BigOperand
|
|
98
|
+
: K extends "Enum" ? V
|
|
99
|
+
: K extends "Optional" ? InputOf<V> | undefined
|
|
100
|
+
: K extends "Flags" ? ReadonlyArray<Extract<V, string>>
|
|
101
|
+
: K extends "ArrayOf" ? ReadonlyArray<ElementInput<V>>
|
|
102
|
+
: K extends "SetOf" ? ReadonlyArray<InputOf<V>>
|
|
103
|
+
: K extends "DictOf" ? { readonly [key: string]: ElementInput<V> | undefined }
|
|
104
|
+
: K extends "MapOf" ? V extends readonly [infer MK, infer MV] ? ReadonlyMap<KeyOfMap<MK>, ElementInput<MV>> : never
|
|
105
|
+
: InputOf<V>
|
|
106
|
+
: T extends Datatype | buffer ? T
|
|
107
|
+
: T extends BigValue ? BigOperand
|
|
108
|
+
: T extends ReadonlyArray<infer E> ? ReadonlyArray<InputOf<E>>
|
|
109
|
+
: T extends ReadonlyMap<infer K, infer V> ? ReadonlyMap<K, InputOf<V>>
|
|
110
|
+
: T extends object ? InputRecord<T>
|
|
111
|
+
: Widen<T>;
|
|
112
|
+
|
|
113
|
+
/** Declared container elements fill omitted record fields from their defaults. */
|
|
114
|
+
export type ElementInput<T> = T extends Declaration<infer K, infer V>
|
|
115
|
+
? K extends "ServerOnly" | "Shared" | "Session" | "Timed" | "Derived" ? ElementInput<V>
|
|
116
|
+
: K extends "Optional" ? ElementInput<V> | undefined
|
|
117
|
+
: InputOf<T>
|
|
118
|
+
: T extends AtomicValue ? InputOf<T>
|
|
119
|
+
: T extends ReadonlyArray<infer E> ? ReadonlyArray<InputOf<E>>
|
|
120
|
+
: T extends ReadonlyMap<infer K, infer V> ? ReadonlyMap<K, InputOf<V>>
|
|
121
|
+
: T extends object ? string extends keyof T ? InputOf<T>
|
|
122
|
+
: number extends keyof T ? InputOf<T>
|
|
123
|
+
: { readonly [K in keyof T]?: ElementInput<T[K]> }
|
|
124
|
+
: InputOf<T>;
|
|
125
|
+
type WriteInput<T, Closed extends boolean> = Closed extends true ? ElementInput<T> : InputOf<T>;
|
|
126
|
+
|
|
127
|
+
type Hidden<T> = T extends ServerOnly<unknown> ? true
|
|
128
|
+
: T extends Declaration<"Shared" | "Session" | "Timed" | "Optional" | "Derived", infer V> ? Hidden<V> : false;
|
|
129
|
+
export type ClientSchema<T> = T extends Declaration<infer K, infer V>
|
|
130
|
+
? K extends "ServerOnly" ? never
|
|
131
|
+
: K extends "MapOf" ? V extends readonly [infer MK, infer MV] ? MapOf<Extract<MK, "integer" | "string">, ClientSchema<MV>> : never
|
|
132
|
+
: K extends "Big" | "Flags" | "Enum" ? T
|
|
133
|
+
: Declaration<K, ClientSchema<V>>
|
|
134
|
+
: T extends AtomicValue ? T
|
|
135
|
+
: T extends ReadonlyArray<infer E> ? ClientSchema<E>[]
|
|
136
|
+
: T extends object ? { [K in keyof T as Hidden<T[K]> extends true ? never : K]: ClientSchema<T[K]> }
|
|
137
|
+
: T;
|
|
138
|
+
type IsShared<T> = T extends Shared<unknown> ? true
|
|
139
|
+
: T extends Session<infer V> ? IsShared<V> : false;
|
|
140
|
+
export type SharedSchema<T> = { [K in keyof T as IsShared<T[K]> extends true ? K : never]: ClientSchema<T[K]> };
|
|
141
|
+
|
|
142
|
+
/** Adapters can depend on this small structural interface without knowing a schema. */
|
|
143
|
+
export interface ReadableNode<T> {
|
|
144
|
+
/** Returns the current value. */
|
|
145
|
+
readonly Get: (this: void) => T;
|
|
146
|
+
/** Calls back now and on changes; returns a disconnect function. */
|
|
147
|
+
readonly Observe: (this: void, callback: (this: void, value: T) => void) => Disconnect;
|
|
148
|
+
/** Calls back on changes with new and old values; returns a disconnect function. */
|
|
149
|
+
readonly Changed: (this: void, callback: (this: void, value: T, previous: T) => void) => Disconnect;
|
|
150
|
+
}
|
|
151
|
+
type Maybe<T, Missing extends boolean> = Missing extends true ? T | undefined : T;
|
|
152
|
+
type Read<T, Missing extends boolean> = Maybe<DeepReadonly<ValueOf<T>>, Missing>;
|
|
153
|
+
interface ReadOperations<T, Missing extends boolean, Closed extends boolean> extends ReadableNode<Read<T, Missing>> {
|
|
154
|
+
/** Calling an accessor without arguments is its Get shorthand. */
|
|
155
|
+
(this: void): Read<T, Missing>;
|
|
156
|
+
/** Returns a detached, mutable copy of the current value. */
|
|
157
|
+
readonly Clone: (this: void) => Maybe<ValueOf<T>, Missing>;
|
|
158
|
+
/** Returns a copy of the declared default, or undefined for an undeclared field. */
|
|
159
|
+
readonly Default: (this: void) => Missing extends true ? Closed extends true ? ValueOf<T> : ValueOf<T> | undefined : ValueOf<T>;
|
|
160
|
+
}
|
|
161
|
+
interface WriteOperations<T, Missing extends boolean, Closed extends boolean> {
|
|
162
|
+
/** Sets the value; shorthand for Set. */
|
|
163
|
+
(this: void, value: WriteInput<T, Closed>, replicate?: boolean): ValueOf<T>;
|
|
164
|
+
/** Updates the value through a callback; shorthand for Update. */
|
|
165
|
+
(this: void, update: (this: void, current: Read<T, Missing>) => WriteInput<T, Closed>, replicate?: boolean): ValueOf<T>;
|
|
166
|
+
/** Validates and sets the value, returning the result. */
|
|
167
|
+
readonly Set: (this: void, value: WriteInput<T, Closed>, replicate?: boolean) => ValueOf<T>;
|
|
168
|
+
/** Passes the current value to the callback and validates its replacement. */
|
|
169
|
+
readonly Update: (this: void, update: (this: void, current: Read<T, Missing>) => WriteInput<T, Closed>, replicate?: boolean) => ValueOf<T>;
|
|
170
|
+
}
|
|
171
|
+
type Unwrap<T> = T extends Declaration<"ServerOnly" | "Shared" | "Session" | "Timed" | "Derived" | "Optional", infer V> ? Unwrap<V> : Exclude<T, undefined>;
|
|
172
|
+
type HasKind<T, Kind extends string> = T extends Declaration<infer K, infer V>
|
|
173
|
+
? K extends Kind ? true : K extends "ServerOnly" | "Shared" | "Session" | "Timed" | "Derived" | "Optional" ? HasKind<V, Kind> : false
|
|
174
|
+
: false;
|
|
175
|
+
type IsReadOnly<T, ReadOnly extends boolean> = ReadOnly extends true ? true : HasKind<T, "Derived">;
|
|
176
|
+
type Mutate<T, Root extends boolean, Missing extends boolean, ReadOnly extends boolean, Closed extends boolean> = Root extends true ? {}
|
|
177
|
+
: IsReadOnly<T, ReadOnly> extends true ? {} : WriteOperations<T, Missing, Closed>;
|
|
178
|
+
type Bound = number | string;
|
|
179
|
+
type AmountOptions = boolean | import("./common").EconomyMeta;
|
|
180
|
+
interface NumberRead {
|
|
181
|
+
/** Returns the declared minimum, or undefined when unbounded. */
|
|
182
|
+
readonly Min: (this: void) => number | undefined;
|
|
183
|
+
/** Returns the declared maximum, or undefined when unbounded. */
|
|
184
|
+
readonly Max: (this: void) => number | undefined;
|
|
185
|
+
}
|
|
186
|
+
interface NumberWrite {
|
|
187
|
+
/** Adds an amount and returns the updated value. */
|
|
188
|
+
readonly Increment: (this: void, amount: number, options?: AmountOptions) => number;
|
|
189
|
+
/** Subtracts an amount and returns the updated value. */
|
|
190
|
+
readonly Decrement: (this: void, amount: number, options?: AmountOptions) => number;
|
|
191
|
+
}
|
|
192
|
+
interface BigRead {
|
|
193
|
+
/** Returns the declared minimum, or undefined when unbounded. */
|
|
194
|
+
readonly Min: (this: void) => Bound | undefined;
|
|
195
|
+
/** Returns the declared maximum, or undefined when unbounded. */
|
|
196
|
+
readonly Max: (this: void) => Bound | undefined;
|
|
197
|
+
}
|
|
198
|
+
interface BigWrite {
|
|
199
|
+
/** Adds an amount and returns the updated Big value. */
|
|
200
|
+
readonly Increment: (this: void, amount: BigOperand, options?: AmountOptions) => BigValue;
|
|
201
|
+
/** Subtracts an amount and returns the updated Big value. */
|
|
202
|
+
readonly Decrement: (this: void, amount: BigOperand, options?: AmountOptions) => BigValue;
|
|
203
|
+
/** Multiplies the field and returns the updated Big value. */
|
|
204
|
+
readonly Multiply: (this: void, amount: BigOperand, replicate?: boolean) => BigValue;
|
|
205
|
+
/** Divides the field and returns the updated Big value; rejects zero. */
|
|
206
|
+
readonly Divide: (this: void, amount: BigOperand, replicate?: boolean) => BigValue;
|
|
207
|
+
}
|
|
208
|
+
type WritableOnly<T, ReadOnly extends boolean, Methods> = IsReadOnly<T, ReadOnly> extends true ? {} : Methods;
|
|
209
|
+
type ScalarMethods<T, ReadOnly extends boolean> = Unwrap<T> extends number ? NumberRead & WritableOnly<T, ReadOnly, NumberWrite>
|
|
210
|
+
: Unwrap<T> extends boolean ? WritableOnly<T, ReadOnly, {
|
|
211
|
+
/** Flips the boolean and returns its new value. */
|
|
212
|
+
readonly Toggle: (this: void, replicate?: boolean) => boolean
|
|
213
|
+
}>
|
|
214
|
+
: Unwrap<T> extends BigSchema | BigValue ? BigRead & WritableOnly<T, ReadOnly, BigWrite> : {};
|
|
215
|
+
|
|
216
|
+
type ChildEvents<K, V> = {
|
|
217
|
+
/** Observes child changes by key; returns a disconnect function. */
|
|
218
|
+
readonly OnChildChanged: (this: void, callback: (this: void, key: K, value: DeepReadonly<V> | undefined, previous: DeepReadonly<V> | undefined) => void) => Disconnect;
|
|
219
|
+
};
|
|
220
|
+
type CollectionRead<K, E, ReadOnly extends boolean, Closed extends boolean, Client extends boolean> = ChildEvents<K, ValueOf<E>> & {
|
|
221
|
+
/** Exact Luau key. Array positions start at 1; map keys are never shifted. */
|
|
222
|
+
readonly Child: (this: void, key: K) => Accessor<E, false, true, ReadOnly, Closed, Client>;
|
|
223
|
+
/** Returns the number of entries. */
|
|
224
|
+
readonly Count: (this: void) => number;
|
|
225
|
+
};
|
|
226
|
+
type ArrayMethods<T, E, ReadOnly extends boolean, Closed extends boolean, Client extends boolean> = CollectionRead<number, E, ReadOnly, Closed, Client> & {
|
|
227
|
+
readonly [index: number]: Accessor<E, false, true, ReadOnly, Closed, Client>;
|
|
228
|
+
/** Returns the first 1-based position, or undefined when absent. */
|
|
229
|
+
readonly Find: (this: void, value: InputOf<E>) => number | undefined;
|
|
230
|
+
/** Checks whether the collection contains the value. */
|
|
231
|
+
readonly Has: (this: void, value: InputOf<E>) => boolean;
|
|
232
|
+
/** Observes insertions with the value and position; returns a disconnect function. */
|
|
233
|
+
readonly OnInsert: (this: void, callback: (this: void, value: DeepReadonly<ValueOf<E>>, index: number) => void) => Disconnect;
|
|
234
|
+
/** Observes removals with the value and former position; returns a disconnect function. */
|
|
235
|
+
readonly OnRemove: (this: void, callback: (this: void, value: DeepReadonly<ValueOf<E>>, index: number) => void) => Disconnect;
|
|
236
|
+
} & WritableOnly<T, ReadOnly, {
|
|
237
|
+
/** Inserts at a 1-based position, or appends when omitted. */
|
|
238
|
+
readonly Insert: (this: void, value: WriteInput<E, Closed>, position?: number, replicate?: boolean) => void;
|
|
239
|
+
/** Removes and returns an entry, defaulting to the last position. */
|
|
240
|
+
readonly Remove: (this: void, position?: number, replicate?: boolean) => ValueOf<E> | undefined;
|
|
241
|
+
/** Removes the first match and returns its value and position, or two undefined values. */
|
|
242
|
+
readonly RemoveValue: (this: void, value: InputOf<E>, replicate?: boolean) => LuaTuple<[ValueOf<E> | undefined, number | undefined]>;
|
|
243
|
+
/** Removes every entry. */
|
|
244
|
+
readonly Clear: (this: void, replicate?: boolean) => void;
|
|
245
|
+
}>;
|
|
246
|
+
type DictMethods<T, K extends string | number, E, ReadOnly extends boolean, Closed extends boolean, Client extends boolean> = CollectionRead<K, E, ReadOnly, Closed, Client> & {
|
|
247
|
+
readonly [P in K]: Accessor<E, false, true, ReadOnly, Closed, Client>;
|
|
248
|
+
} & {
|
|
249
|
+
/** Observes new keys and their values; returns a disconnect function. */
|
|
250
|
+
readonly OnKeyAdded: (this: void, callback: (this: void, key: K, value: DeepReadonly<ValueOf<E>>) => void) => Disconnect;
|
|
251
|
+
/** Observes removed keys and their values; returns a disconnect function. */
|
|
252
|
+
readonly OnKeyRemoved: (this: void, callback: (this: void, key: K, value: DeepReadonly<ValueOf<E>>) => void) => Disconnect;
|
|
253
|
+
} & WritableOnly<T, ReadOnly, {
|
|
254
|
+
/** Removes the key and returns its previous value, or undefined when absent. */
|
|
255
|
+
readonly Remove: (this: void, key: K, replicate?: boolean) => ValueOf<E> | undefined;
|
|
256
|
+
/** Removes every entry. */
|
|
257
|
+
readonly Clear: (this: void, replicate?: boolean) => void;
|
|
258
|
+
}>;
|
|
259
|
+
type SetMethods<T, E, ReadOnly extends boolean> = {
|
|
260
|
+
/** Checks whether the collection contains the value. */
|
|
261
|
+
readonly Has: (this: void, value: InputOf<E>) => boolean;
|
|
262
|
+
/** Returns the first 1-based position, or undefined when absent. */
|
|
263
|
+
readonly Find: (this: void, value: InputOf<E>) => number | undefined;
|
|
264
|
+
/** Returns the number of entries. */
|
|
265
|
+
readonly Count: (this: void) => number;
|
|
266
|
+
} & WritableOnly<T, ReadOnly, {
|
|
267
|
+
/** Adds a set member; returns false if already present. */
|
|
268
|
+
readonly Add: (this: void, value: InputOf<E>, replicate?: boolean) => boolean;
|
|
269
|
+
/** Removes a set member; returns false if absent. */
|
|
270
|
+
readonly Remove: (this: void, value: InputOf<E>, replicate?: boolean) => boolean;
|
|
271
|
+
/** Removes every entry. */
|
|
272
|
+
readonly Clear: (this: void, replicate?: boolean) => void;
|
|
273
|
+
}>;
|
|
274
|
+
type FlagsMethods<T, K extends string, ReadOnly extends boolean> = {
|
|
275
|
+
/** Checks whether the flag is enabled. */
|
|
276
|
+
readonly Has: (this: void, member: K) => boolean;
|
|
277
|
+
} & WritableOnly<T, ReadOnly, {
|
|
278
|
+
/** Enables the named flag. */
|
|
279
|
+
readonly Enable: (this: void, member: K, replicate?: boolean) => void;
|
|
280
|
+
/** Disables the named flag. */
|
|
281
|
+
readonly Disable: (this: void, member: K, replicate?: boolean) => void;
|
|
282
|
+
/** Flips the named flag and returns whether it is enabled. */
|
|
283
|
+
readonly Toggle: (this: void, member: K, replicate?: boolean) => boolean;
|
|
284
|
+
/** Disables every flag. */
|
|
285
|
+
readonly Clear: (this: void, replicate?: boolean) => void;
|
|
286
|
+
}>;
|
|
287
|
+
type ReservedMethod = "Get" | "Set" | "Update" | "Clone" | "Default" | "Changed" | "Observe" | "Child" |
|
|
288
|
+
"OnChildChanged" | "Count" | "Clear" | "Insert" | "Remove" | "RemoveValue" | "Find" | "Has" |
|
|
289
|
+
"OnInsert" | "OnRemove" | "OnKeyAdded" | "OnKeyRemoved" | "Increment" | "Decrement" | "Min" | "Max" |
|
|
290
|
+
"Toggle" | "Enable" | "Disable" | "Add" | "Multiply" | "Divide" | "SetTimed" | "ExtendTimed" | "Active";
|
|
291
|
+
type ChildMissing<T, Missing extends boolean> = Missing extends true ? true : OptionalField<T>;
|
|
292
|
+
type RecordMethods<T, S, Missing extends boolean, ReadOnly extends boolean, Closed extends boolean, Client extends boolean> = {
|
|
293
|
+
readonly [K in keyof S as K extends ReservedMethod ? never : K]-?: Accessor<S[K], false, ChildMissing<T, Missing>, IsReadOnly<T, ReadOnly>, Closed, Client>;
|
|
294
|
+
} & {
|
|
295
|
+
/** Accesses a child by name, including keys that match methods. */
|
|
296
|
+
readonly Child: <K extends Extract<keyof S, string | number>>(this: void, key: K) => Accessor<S[K], false, ChildMissing<T, Missing>, IsReadOnly<T, ReadOnly>, Closed, Client>;
|
|
297
|
+
} & ChildEvents<Extract<keyof S, string | number>, ValueOf<S[keyof S]>>;
|
|
298
|
+
|
|
299
|
+
type ShapeMethods<T, S, Missing extends boolean, ReadOnly extends boolean, Closed extends boolean, Client extends boolean> = S extends ArrayOf<infer E>
|
|
300
|
+
? ArrayMethods<T, E, ReadOnly, true, Client>
|
|
301
|
+
: S extends DictOf<infer E> ? DictMethods<T, string, E, ReadOnly, true, Client>
|
|
302
|
+
: S extends MapOf<infer K, infer E> ? DictMethods<T, KeyOfMap<K>, E, ReadOnly, true, Client>
|
|
303
|
+
: S extends SetOf<infer E> ? SetMethods<T, E, ReadOnly>
|
|
304
|
+
: S extends Flags<infer K> ? FlagsMethods<T, K, ReadOnly>
|
|
305
|
+
: S extends Declaration<string, unknown> | AtomicValue ? {}
|
|
306
|
+
: S extends ReadonlyArray<infer E> ? ArrayMethods<T, E, ReadOnly, false, Client>
|
|
307
|
+
: S extends object ? string extends keyof S ? DictMethods<T, string, S[string & keyof S], ReadOnly, false, Client>
|
|
308
|
+
: number extends keyof S ? ArrayMethods<T, S[number & keyof S], ReadOnly, false, Client>
|
|
309
|
+
: RecordMethods<T, S, Missing, ReadOnly, Closed, Client>
|
|
310
|
+
: {};
|
|
311
|
+
// Only the server changes timer deadlines.
|
|
312
|
+
type TimedMethods<T, ReadOnly extends boolean, Client extends boolean> = HasKind<T, "Timed"> extends true ? {
|
|
313
|
+
/** Timer state and seconds left. Clients read replicated deadlines; inactive returns false, undefined. */
|
|
314
|
+
readonly Active: (this: void) => LuaTuple<[boolean, number | undefined]>;
|
|
315
|
+
} & WritableOnly<T, Client extends true ? true : ReadOnly, {
|
|
316
|
+
/** Sets the value until its timer expires, then restores the default; server only. */
|
|
317
|
+
readonly SetTimed: (this: void, value: InputOf<T>, seconds: number, replicate?: boolean) => void;
|
|
318
|
+
/** Adds seconds to the timer, starting from now if inactive; server only. */
|
|
319
|
+
readonly ExtendTimed: (this: void, seconds: number, replicate?: boolean) => void;
|
|
320
|
+
}> : {};
|
|
321
|
+
|
|
322
|
+
/** Proxy objects, not native Array/Map instances. Client omits SetTimed/ExtendTimed. */
|
|
323
|
+
export type Accessor<T, Root extends boolean = false, Missing extends boolean = false, ReadOnly extends boolean = false, Closed extends boolean = false, Client extends boolean = false> =
|
|
324
|
+
ReadOperations<T, Missing, Closed> & Mutate<T, Root, Missing, ReadOnly, Closed> & ScalarMethods<T, ReadOnly> &
|
|
325
|
+
ShapeMethods<T, Unwrap<T>, Missing, ReadOnly, Closed, Client> & TimedMethods<T, ReadOnly, Client>;
|
|
326
|
+
export type PlayerData<T> = Accessor<T, true>;
|
|
327
|
+
export type ReadonlyAccessor<T, Root extends boolean = false> = Accessor<T, Root, false, true>;
|
|
328
|
+
|
|
329
|
+
type Join<K extends string, P> = P extends string ? `${K}.${P}` : never;
|
|
330
|
+
/** Static numeric leaf paths only. Dynamic keys require a runtime-validated path. */
|
|
331
|
+
export type NumericPaths<T, IncludeBig extends boolean = false, Depth extends unknown[] = []> =
|
|
332
|
+
Depth extends [unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown] ? never
|
|
333
|
+
: Unwrap<T> extends number ? ""
|
|
334
|
+
: Unwrap<T> extends BigSchema | BigValue ? IncludeBig extends true ? "" : never
|
|
335
|
+
: Unwrap<T> extends AtomicValue | Declaration<string, unknown> | ReadonlyArray<unknown> ? never
|
|
336
|
+
: Unwrap<T> extends object ? {
|
|
337
|
+
[K in Extract<keyof Unwrap<T>, string>]: string extends K ? never :
|
|
338
|
+
NumericPaths<Unwrap<T>[K], IncludeBig, [...Depth, unknown]> extends infer P
|
|
339
|
+
? P extends "" ? K : Join<K, P> : never
|
|
340
|
+
}[Extract<keyof Unwrap<T>, string>] : never;
|