@rbxts/scribe 2.5.0 → 2.6.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.
- 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/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/Store/ProfileStore.luau +21 -0
- package/src/Internal/Template.luau +78 -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 +230 -21
- package/src/Server/Timed.luau +2 -2
- package/src/Types.luau +3 -1
- package/src/init.luau +137 -71
- package/types/api.d.ts +253 -252
- package/types/common.d.ts +357 -355
- package/types/index.d.ts +226 -226
- package/types/schema.d.ts +276 -276
package/src/init.luau
CHANGED
|
@@ -69,8 +69,30 @@ export type EconomyLogFn = Types.EconomyLogFn
|
|
|
69
69
|
-- the recursive typed accessor tree.
|
|
70
70
|
--------------------------------------------------------------------------------
|
|
71
71
|
|
|
72
|
+
-- Copy these small signatures to retain editor labels without changing node types.
|
|
73
|
+
type NodeFunctionNames = {
|
|
74
|
+
Listener: (callback: any) -> (),
|
|
75
|
+
Value: (value: any) -> (),
|
|
76
|
+
Change: (newValue: any, oldValue: any) -> (),
|
|
77
|
+
ChildChange: (key: any, newValue: any, oldValue: any) -> (),
|
|
78
|
+
IndexedValue: (value: any, index: any) -> (),
|
|
79
|
+
KeyValue: (key: any, value: any) -> (),
|
|
80
|
+
Set: (value: any, replicate: any) -> (),
|
|
81
|
+
Update: (callback: any, replicate: any) -> (),
|
|
82
|
+
Increment: (delta: any, tagsOrReplicate: any) -> (),
|
|
83
|
+
Insert: (value: any, index: any, replicate: any) -> (),
|
|
84
|
+
RemoveIndex: (index: any, replicate: any) -> (),
|
|
85
|
+
RemoveKey: (key: any, replicate: any) -> (),
|
|
86
|
+
Key: (key: any) -> (),
|
|
87
|
+
Flag: (name: any) -> (),
|
|
88
|
+
FlagWrite: (name: any, replicate: any) -> (),
|
|
89
|
+
Replicate: (replicate: any) -> (),
|
|
90
|
+
SetTimed: (value: any, seconds: any, replicate: any) -> (),
|
|
91
|
+
ExtendTimed: (seconds: any, replicate: any) -> (),
|
|
92
|
+
}
|
|
93
|
+
|
|
72
94
|
-- selene: allow(undefined_variable) -- `types` is the type-function runtime library
|
|
73
|
-
|
|
95
|
+
type function BuildValueType(T, Names: type?)
|
|
74
96
|
local ts = types
|
|
75
97
|
|
|
76
98
|
local nilType = ts.singleton(nil)
|
|
@@ -83,7 +105,16 @@ export type function ValueType(T)
|
|
|
83
105
|
local optBool = optional(ts.boolean)
|
|
84
106
|
local optNumber = optional(ts.number)
|
|
85
107
|
|
|
86
|
-
local function fn(params: { type }, rets: { type }): type
|
|
108
|
+
local function fn(params: { type }, rets: { type }, name: string?): type
|
|
109
|
+
if name ~= nil and Names ~= nil then
|
|
110
|
+
local prototype = Names:readproperty(ts.singleton(name))
|
|
111
|
+
if prototype ~= nil then
|
|
112
|
+
local result = ts.copy(prototype)
|
|
113
|
+
result:setparameters(params)
|
|
114
|
+
result:setreturns(rets)
|
|
115
|
+
return result
|
|
116
|
+
end
|
|
117
|
+
end
|
|
87
118
|
return ts.newfunction({ head = params }, { head = rets })
|
|
88
119
|
end
|
|
89
120
|
|
|
@@ -467,7 +498,7 @@ export type function ValueType(T)
|
|
|
467
498
|
if childType ~= nil then
|
|
468
499
|
local childNode = build(childType, false, depth + 1)
|
|
469
500
|
table.insert(props, { key = key, ty = childNode })
|
|
470
|
-
table.insert(childLookups, fn({ key }, { childNode }))
|
|
501
|
+
table.insert(childLookups, fn({ key }, { childNode }, "Key"))
|
|
471
502
|
end
|
|
472
503
|
end
|
|
473
504
|
|
|
@@ -491,34 +522,46 @@ export type function ValueType(T)
|
|
|
491
522
|
-- Array node: the indexer makes `arr[i]` an accessor node, which is
|
|
492
523
|
-- the only way to reach a Scribe.ArrayOf element field.
|
|
493
524
|
local elemNode = build(indexer.readresult, false, depth + 1)
|
|
494
|
-
table.insert(childLookups, fn({ indexer.index }, { elemNode }))
|
|
525
|
+
table.insert(childLookups, fn({ indexer.index }, { elemNode }, "Key"))
|
|
495
526
|
indexerSpec = {
|
|
496
527
|
index = indexer.index,
|
|
497
528
|
readresult = elemNode,
|
|
498
529
|
writeresult = elemNode,
|
|
499
530
|
}
|
|
500
|
-
add("Insert", fn({ elementIn, optNumber, optBool }, {}))
|
|
531
|
+
add("Insert", fn({ elementIn, optNumber, optBool }, {}, "Insert"))
|
|
501
532
|
-- Remove returns nil on an empty/missing array (matches RemoveValue).
|
|
502
|
-
add("Remove", fn({ optNumber, optBool }, { optional(elementType) }))
|
|
503
|
-
add("RemoveValue", fn({ elementIn, optBool }, { optional(elementType), optNumber }))
|
|
504
|
-
add("Find", fn({ elementIn }, { optNumber }))
|
|
505
|
-
add("Has", fn({ elementIn }, { ts.boolean }))
|
|
506
|
-
add(
|
|
507
|
-
|
|
533
|
+
add("Remove", fn({ optNumber, optBool }, { optional(elementType) }, "RemoveIndex"))
|
|
534
|
+
add("RemoveValue", fn({ elementIn, optBool }, { optional(elementType), optNumber }, "Set"))
|
|
535
|
+
add("Find", fn({ elementIn }, { optNumber }, "Value"))
|
|
536
|
+
add("Has", fn({ elementIn }, { ts.boolean }, "Value"))
|
|
537
|
+
add(
|
|
538
|
+
"OnInsert",
|
|
539
|
+
fn({ fn({ elementType, ts.number }, {}, "IndexedValue") }, { disconnectType }, "Listener")
|
|
540
|
+
)
|
|
541
|
+
add(
|
|
542
|
+
"OnRemove",
|
|
543
|
+
fn({ fn({ elementType, ts.number }, {}, "IndexedValue") }, { disconnectType }, "Listener")
|
|
544
|
+
)
|
|
508
545
|
else
|
|
509
546
|
-- Dictionary node: children are accessor nodes.
|
|
510
547
|
local childNode = build(indexer.readresult, false, depth + 1)
|
|
511
|
-
table.insert(childLookups, fn({ indexer.index }, { childNode }))
|
|
548
|
+
table.insert(childLookups, fn({ indexer.index }, { childNode }, "Key"))
|
|
512
549
|
indexerSpec = {
|
|
513
550
|
index = indexer.index,
|
|
514
551
|
readresult = childNode,
|
|
515
552
|
writeresult = childNode,
|
|
516
553
|
}
|
|
517
|
-
add("Remove", fn({ ts.string, optBool }, { optional(elementType) }))
|
|
518
|
-
add(
|
|
519
|
-
|
|
554
|
+
add("Remove", fn({ ts.string, optBool }, { optional(elementType) }, "RemoveKey"))
|
|
555
|
+
add(
|
|
556
|
+
"OnKeyAdded",
|
|
557
|
+
fn({ fn({ indexer.index, elementType }, {}, "KeyValue") }, { disconnectType }, "Listener")
|
|
558
|
+
)
|
|
559
|
+
add(
|
|
560
|
+
"OnKeyRemoved",
|
|
561
|
+
fn({ fn({ indexer.index, elementType }, {}, "KeyValue") }, { disconnectType }, "Listener")
|
|
562
|
+
)
|
|
520
563
|
end
|
|
521
|
-
add("Clear", fn({ optBool }, {}))
|
|
564
|
+
add("Clear", fn({ optBool }, {}, "Replicate"))
|
|
522
565
|
add("Count", fn({}, { ts.number }))
|
|
523
566
|
-- A dynamic container's children are homogeneous, so the key and value
|
|
524
567
|
-- types here are exact rather than a union over declared fields.
|
|
@@ -536,7 +579,10 @@ export type function ValueType(T)
|
|
|
536
579
|
local childValue = if #childValues > MAX_CHILD_UNION
|
|
537
580
|
then optional(anyType)
|
|
538
581
|
else optional(ts.unionof(table.unpack(childValues)))
|
|
539
|
-
add(
|
|
582
|
+
add(
|
|
583
|
+
"OnChildChanged",
|
|
584
|
+
fn({ fn({ childKey, childValue, childValue }, {}, "ChildChange") }, { disconnectType }, "Listener")
|
|
585
|
+
)
|
|
540
586
|
end
|
|
541
587
|
end
|
|
542
588
|
|
|
@@ -545,13 +591,20 @@ export type function ValueType(T)
|
|
|
545
591
|
-- events and Remove carry the element rather than the whole map.
|
|
546
592
|
local element = mapElement :: type
|
|
547
593
|
local childNode = build(mapValue :: type, false, depth + 1)
|
|
548
|
-
table.insert(childLookups, fn({ mapKey }, { childNode }))
|
|
594
|
+
table.insert(childLookups, fn({ mapKey }, { childNode }, "Key"))
|
|
549
595
|
indexerSpec = { index = mapKey, readresult = childNode, writeresult = childNode }
|
|
550
|
-
add("Remove", fn({ mapKey, optBool }, { optional(element) }))
|
|
551
|
-
add("OnKeyAdded", fn({ fn({ mapKey, element }, {}) }, { disconnectType }))
|
|
552
|
-
add("OnKeyRemoved", fn({ fn({ mapKey, element }, {}) }, { disconnectType }))
|
|
553
|
-
add(
|
|
554
|
-
|
|
596
|
+
add("Remove", fn({ mapKey, optBool }, { optional(element) }, "RemoveKey"))
|
|
597
|
+
add("OnKeyAdded", fn({ fn({ mapKey, element }, {}, "KeyValue") }, { disconnectType }, "Listener"))
|
|
598
|
+
add("OnKeyRemoved", fn({ fn({ mapKey, element }, {}, "KeyValue") }, { disconnectType }, "Listener"))
|
|
599
|
+
add(
|
|
600
|
+
"OnChildChanged",
|
|
601
|
+
fn(
|
|
602
|
+
{ fn({ mapKey, optional(element), optional(element) }, {}, "ChildChange") },
|
|
603
|
+
{ disconnectType },
|
|
604
|
+
"Listener"
|
|
605
|
+
)
|
|
606
|
+
)
|
|
607
|
+
add("Clear", fn({ optBool }, {}, "Replicate"))
|
|
555
608
|
add("Count", fn({}, { ts.number }))
|
|
556
609
|
end
|
|
557
610
|
|
|
@@ -562,7 +615,7 @@ export type function ValueType(T)
|
|
|
562
615
|
if #childLookups == 1 then
|
|
563
616
|
add("Child", childLookups[1])
|
|
564
617
|
elseif #childLookups > 1 then
|
|
565
|
-
add("Child", fn({ ts.unionof(ts.string, ts.number) }, { anyType }))
|
|
618
|
+
add("Child", fn({ ts.unionof(ts.string, ts.number) }, { anyType }, "Key"))
|
|
566
619
|
end
|
|
567
620
|
|
|
568
621
|
-- Common node methods.
|
|
@@ -578,39 +631,39 @@ export type function ValueType(T)
|
|
|
578
631
|
then ts.newtable(nil, { index = mapKey, readresult = mapElement, writeresult = mapElement }, nil)
|
|
579
632
|
else valueType
|
|
580
633
|
local writeIn = if mapKey ~= nil then writeType else readOnlyDeep(writeType, depth + 1)
|
|
581
|
-
add("Set", fn({ writeIn, optBool }, { valueType }))
|
|
582
|
-
add("Update", fn({ fn({ valueType }, { writeIn }), optBool }, { valueType }))
|
|
634
|
+
add("Set", fn({ writeIn, optBool }, { valueType }, "Set"))
|
|
635
|
+
add("Update", fn({ fn({ valueType }, { writeIn }, "Value"), optBool }, { valueType }, "Update"))
|
|
583
636
|
end
|
|
584
637
|
add("Clone", fn({}, { valueType }))
|
|
585
638
|
add("Default", fn({}, { valueType }))
|
|
586
639
|
-- (new, old) on every node. On a container it reports state, coalesced to one
|
|
587
640
|
-- fire per batch or received frame; which child moved is OnChildChanged's job.
|
|
588
|
-
add("Changed", fn({ fn({ valueType, valueType }, {}) }, { disconnectType }))
|
|
589
|
-
add("Observe", fn({ fn({ valueType }, {}) }, { disconnectType }))
|
|
641
|
+
add("Changed", fn({ fn({ valueType, valueType }, {}, "Change") }, { disconnectType }, "Listener"))
|
|
642
|
+
add("Observe", fn({ fn({ valueType }, {}, "Value") }, { disconnectType }, "Listener"))
|
|
590
643
|
|
|
591
644
|
if t:is("number") then
|
|
592
645
|
-- Min/Max read the declared bounds, so they stay on a derived field; the
|
|
593
646
|
-- two mutators do not.
|
|
594
647
|
if not isDerived then
|
|
595
|
-
add("Increment", fn({ ts.number, anyType }, { ts.number }))
|
|
596
|
-
add("Decrement", fn({ ts.number, anyType }, { ts.number }))
|
|
648
|
+
add("Increment", fn({ ts.number, anyType }, { ts.number }, "Increment"))
|
|
649
|
+
add("Decrement", fn({ ts.number, anyType }, { ts.number }, "Increment"))
|
|
597
650
|
end
|
|
598
651
|
add("Min", fn({}, { optNumber }))
|
|
599
652
|
add("Max", fn({}, { optNumber }))
|
|
600
653
|
elseif t:is("boolean") and not isDerived then
|
|
601
|
-
add("Toggle", fn({ optBool }, { ts.boolean }))
|
|
654
|
+
add("Toggle", fn({ optBool }, { ts.boolean }, "Replicate"))
|
|
602
655
|
end
|
|
603
656
|
|
|
604
657
|
if isBig then
|
|
605
658
|
-- Every entry point, Set included, takes a number, a numeric string, or
|
|
606
659
|
-- another big value, so the operand type is the same union everywhere.
|
|
607
660
|
local operand = ts.unionof(ts.number, ts.string, valueType)
|
|
608
|
-
add("Set", fn({ operand, optBool }, { valueType }))
|
|
609
|
-
add("Update", fn({ fn({ valueType }, { operand }), optBool }, { valueType }))
|
|
610
|
-
add("Increment", fn({ operand, anyType }, { valueType }))
|
|
611
|
-
add("Decrement", fn({ operand, anyType }, { valueType }))
|
|
612
|
-
add("Multiply", fn({ operand, optBool }, { valueType }))
|
|
613
|
-
add("Divide", fn({ operand, optBool }, { valueType }))
|
|
661
|
+
add("Set", fn({ operand, optBool }, { valueType }, "Set"))
|
|
662
|
+
add("Update", fn({ fn({ valueType }, { operand }, "Value"), optBool }, { valueType }, "Update"))
|
|
663
|
+
add("Increment", fn({ operand, anyType }, { valueType }, "Increment"))
|
|
664
|
+
add("Decrement", fn({ operand, anyType }, { valueType }, "Increment"))
|
|
665
|
+
add("Multiply", fn({ operand, optBool }, { valueType }, "Set"))
|
|
666
|
+
add("Divide", fn({ operand, optBool }, { valueType }, "Set"))
|
|
614
667
|
-- A big bound past the double range is only expressible as a numeric string,
|
|
615
668
|
-- so these return the same union the declarator accepts.
|
|
616
669
|
local optBound = optional(ts.unionof(ts.number, ts.string))
|
|
@@ -623,25 +676,25 @@ export type function ValueType(T)
|
|
|
623
676
|
local setIndexer = t:indexer()
|
|
624
677
|
local element = if setIndexer ~= nil then widen(setIndexer.readresult) else anyType
|
|
625
678
|
local elementIn = readOnlyDeep(element, depth + 1)
|
|
626
|
-
add("Add", fn({ elementIn, optBool }, { ts.boolean }))
|
|
627
|
-
add("Remove", fn({ elementIn, optBool }, { ts.boolean }))
|
|
628
|
-
add("Has", fn({ elementIn }, { ts.boolean }))
|
|
679
|
+
add("Add", fn({ elementIn, optBool }, { ts.boolean }, "Set"))
|
|
680
|
+
add("Remove", fn({ elementIn, optBool }, { ts.boolean }, "Set"))
|
|
681
|
+
add("Has", fn({ elementIn }, { ts.boolean }, "Value"))
|
|
629
682
|
add("Count", fn({}, { ts.number }))
|
|
630
|
-
add("Clear", fn({ optBool }, {}))
|
|
683
|
+
add("Clear", fn({ optBool }, {}, "Replicate"))
|
|
631
684
|
end
|
|
632
685
|
|
|
633
686
|
if isFlags then
|
|
634
687
|
-- Named-member surface. Get/Set still take the whole { string } set.
|
|
635
|
-
add("Enable", fn({ ts.string, optBool }, {}))
|
|
636
|
-
add("Disable", fn({ ts.string, optBool }, {}))
|
|
637
|
-
add("Has", fn({ ts.string }, { ts.boolean }))
|
|
638
|
-
add("Toggle", fn({ ts.string, optBool }, { ts.boolean }))
|
|
639
|
-
add("Clear", fn({ optBool }, {}))
|
|
688
|
+
add("Enable", fn({ ts.string, optBool }, {}, "FlagWrite"))
|
|
689
|
+
add("Disable", fn({ ts.string, optBool }, {}, "FlagWrite"))
|
|
690
|
+
add("Has", fn({ ts.string }, { ts.boolean }, "Flag"))
|
|
691
|
+
add("Toggle", fn({ ts.string, optBool }, { ts.boolean }, "FlagWrite"))
|
|
692
|
+
add("Clear", fn({ optBool }, {}, "Replicate"))
|
|
640
693
|
end
|
|
641
694
|
|
|
642
695
|
if isTimed then
|
|
643
|
-
add("SetTimed", fn({ valueType, ts.number, optBool }, {}))
|
|
644
|
-
add("ExtendTimed", fn({ ts.number, optBool }, {}))
|
|
696
|
+
add("SetTimed", fn({ valueType, ts.number, optBool }, {}, "SetTimed"))
|
|
697
|
+
add("ExtendTimed", fn({ ts.number, optBool }, {}, "ExtendTimed"))
|
|
645
698
|
add("Active", fn({}, { ts.boolean, optNumber }))
|
|
646
699
|
end
|
|
647
700
|
|
|
@@ -658,6 +711,12 @@ export type function ValueType(T)
|
|
|
658
711
|
return build(T, true, 0)
|
|
659
712
|
end
|
|
660
713
|
|
|
714
|
+
-- Keep the original type-function arity for existing callers.
|
|
715
|
+
-- selene: allow(undefined_variable)
|
|
716
|
+
export type function ValueType(T)
|
|
717
|
+
return BuildValueType(T, nil)
|
|
718
|
+
end
|
|
719
|
+
|
|
661
720
|
-- Union of every static rankable leaf path in the template, dot-joined ("Coins",
|
|
662
721
|
-- "Stats.Wins"), for leaderboard `Stat` and purchase cost paths. Dynamic segments cannot
|
|
663
722
|
-- be enumerated at type level, so those paths must be cast to `any`; falls back to plain
|
|
@@ -818,16 +877,21 @@ end
|
|
|
818
877
|
-- Grant callbacks receive the typed accessor tree when a template type is supplied,
|
|
819
878
|
-- and stay `any` for the untyped default so un-annotated configs stay clean.
|
|
820
879
|
-- selene: allow(undefined_variable)
|
|
821
|
-
|
|
880
|
+
type function BuildGrantDataType(T, Names: type?)
|
|
822
881
|
if T:is("any") or T:is("unknown") then
|
|
823
882
|
return types.any
|
|
824
883
|
end
|
|
825
|
-
return
|
|
884
|
+
return BuildValueType(T, Names)
|
|
885
|
+
end
|
|
886
|
+
|
|
887
|
+
-- selene: allow(undefined_variable)
|
|
888
|
+
export type function GrantDataType(T)
|
|
889
|
+
return BuildGrantDataType(T, nil)
|
|
826
890
|
end
|
|
827
891
|
|
|
828
892
|
-- Store proxies expose declared roots, without the root accessor's methods.
|
|
829
893
|
-- selene: allow(undefined_variable)
|
|
830
|
-
type function StoreDataType(S: type): type
|
|
894
|
+
type function StoreDataType(S: type, Names: type?): type
|
|
831
895
|
local ts = types
|
|
832
896
|
if not S:is("table") then
|
|
833
897
|
return ts.any
|
|
@@ -846,7 +910,7 @@ type function StoreDataType(S: type): type
|
|
|
846
910
|
names[key] = alias
|
|
847
911
|
end
|
|
848
912
|
end
|
|
849
|
-
local nodes =
|
|
913
|
+
local nodes = BuildValueType(fields, Names)
|
|
850
914
|
local roots = ts.newtable(nil, nodes:indexer(), nil)
|
|
851
915
|
for key, alias in names do
|
|
852
916
|
roots:setproperty(key, nodes:readproperty(alias))
|
|
@@ -858,7 +922,7 @@ end
|
|
|
858
922
|
-- rather than `ValueType<T> & { ... }`, because normalizing an intersection over a
|
|
859
923
|
-- large accessor tree exceeds the solver's budget at the Scribe() call site.
|
|
860
924
|
-- selene: allow(undefined_variable)
|
|
861
|
-
type function BuildClientDataType(T, S)
|
|
925
|
+
type function BuildClientDataType(T, S, Names: type?)
|
|
862
926
|
local ts = types
|
|
863
927
|
|
|
864
928
|
local function optional(t: type): type
|
|
@@ -903,7 +967,7 @@ type function BuildClientDataType(T, S)
|
|
|
903
967
|
saveInfoProps[ts.singleton("Size")] = optional(ts.number)
|
|
904
968
|
local saveInfo = ts.newtable(saveInfoProps, nil, nil)
|
|
905
969
|
|
|
906
|
-
local out = ts.copy(
|
|
970
|
+
local out = ts.copy(BuildValueType(StripServerOnly(T), Names))
|
|
907
971
|
local function add(name: string, ty: type)
|
|
908
972
|
out:setproperty(ts.singleton(name), ty)
|
|
909
973
|
end
|
|
@@ -954,24 +1018,24 @@ type function BuildClientDataType(T, S)
|
|
|
954
1018
|
ts.newfunction({ head = { ts.string, ts.newfunction({ tail = ts.any }, { tail = ts.any }) } }, { head = {} })
|
|
955
1019
|
)
|
|
956
1020
|
add("Raw", ts.any)
|
|
957
|
-
add("ServerStore", StoreDataType(StripServerOnly(S)))
|
|
1021
|
+
add("ServerStore", StoreDataType(StripServerOnly(S), Names))
|
|
958
1022
|
|
|
959
1023
|
return out
|
|
960
1024
|
end
|
|
961
1025
|
|
|
962
1026
|
-- selene: allow(undefined_variable)
|
|
963
1027
|
export type function ClientDataType(T)
|
|
964
|
-
return BuildClientDataType(T, types.any)
|
|
1028
|
+
return BuildClientDataType(T, types.any, nil)
|
|
965
1029
|
end
|
|
966
1030
|
|
|
967
1031
|
-- The server `Data` API. P is the Player class type, passed in as a type argument
|
|
968
1032
|
-- because class types are not constructible inside a type function. A type function
|
|
969
1033
|
-- for the same complexity-budget reason as ClientDataType.
|
|
970
1034
|
-- selene: allow(undefined_variable)
|
|
971
|
-
type function BuildServerDataType(T, P, S)
|
|
1035
|
+
type function BuildServerDataType(T, P, S, Names: type?)
|
|
972
1036
|
local ts = types
|
|
973
1037
|
|
|
974
|
-
local node =
|
|
1038
|
+
local node = BuildValueType(T, Names)
|
|
975
1039
|
|
|
976
1040
|
local function optional(t: type): type
|
|
977
1041
|
return ts.unionof(t, ts.singleton(nil))
|
|
@@ -1002,7 +1066,8 @@ type function BuildServerDataType(T, P, S)
|
|
|
1002
1066
|
)
|
|
1003
1067
|
bigScoreProps[ts.singleton("ToNumber")] = ts.newfunction({ head = { ts.any } }, { head = { ts.number } })
|
|
1004
1068
|
bigScoreProps[ts.singleton("Log10")] = ts.newfunction({ head = { ts.any } }, { head = { ts.number } })
|
|
1005
|
-
|
|
1069
|
+
local bigScore = ts.newtable(bigScoreProps, nil, nil)
|
|
1070
|
+
entryProps[ts.singleton("Score")] = ts.unionof(ts.number, bigScore)
|
|
1006
1071
|
local leaderboardEntry = ts.newtable(entryProps, nil, nil)
|
|
1007
1072
|
local entryArray =
|
|
1008
1073
|
ts.newtable(nil, { index = ts.number, readresult = leaderboardEntry, writeresult = leaderboardEntry }, nil)
|
|
@@ -1135,10 +1200,10 @@ type function BuildServerDataType(T, P, S)
|
|
|
1135
1200
|
-- Purchase spec: Cost.Path is the template's numeric-leaf path union and
|
|
1136
1201
|
-- Grant receives the typed accessor tree.
|
|
1137
1202
|
local costProps: { [type]: type } = {}
|
|
1138
|
-
--
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
costProps[ts.singleton("Amount")] = ts.number
|
|
1203
|
+
-- Include Big currency paths.
|
|
1204
|
+
costProps[ts.singleton("Path")] = StatPathsType(T, ts.singleton(true))
|
|
1205
|
+
-- Validate path/amount pairs at runtime to avoid a costly per-path type union.
|
|
1206
|
+
costProps[ts.singleton("Amount")] = ts.unionof(ts.number, ts.string, bigScore)
|
|
1142
1207
|
local purchaseProps: { [type]: type } = {}
|
|
1143
1208
|
purchaseProps[ts.singleton("Cost")] = ts.newtable(costProps, nil, nil)
|
|
1144
1209
|
purchaseProps[ts.singleton("Category")] = optional(ts.string)
|
|
@@ -1211,14 +1276,14 @@ type function BuildServerDataType(T, P, S)
|
|
|
1211
1276
|
add("SendMessage", fn({ ts.number, ts.any }, { ts.boolean }))
|
|
1212
1277
|
add("ProfileStore", ts.any)
|
|
1213
1278
|
add("Raw", ts.any)
|
|
1214
|
-
add("ServerStore", StoreDataType(S))
|
|
1279
|
+
add("ServerStore", StoreDataType(S, Names))
|
|
1215
1280
|
|
|
1216
1281
|
return ts.newtable(props, { index = P, readresult = node, writeresult = node }, nil)
|
|
1217
1282
|
end
|
|
1218
1283
|
|
|
1219
1284
|
-- selene: allow(undefined_variable)
|
|
1220
1285
|
export type function ServerDataType(T, P)
|
|
1221
|
-
return BuildServerDataType(T, P, types.any)
|
|
1286
|
+
return BuildServerDataType(T, P, types.any, nil)
|
|
1222
1287
|
end
|
|
1223
1288
|
|
|
1224
1289
|
--------------------------------------------------------------------------------
|
|
@@ -1321,15 +1386,16 @@ export type LeaderboardConfig<T = any> = {
|
|
|
1321
1386
|
export type ProductConfig<T = any> = {
|
|
1322
1387
|
Id: number,
|
|
1323
1388
|
Category: string?,
|
|
1324
|
-
Grant: ((data:
|
|
1389
|
+
Grant: ((data: BuildGrantDataType<T, NodeFunctionNames>) -> ())?,
|
|
1325
1390
|
Grants: string?,
|
|
1326
1391
|
}
|
|
1327
1392
|
|
|
1328
1393
|
export type PurchaseSpec<T = any> = {
|
|
1329
|
-
|
|
1394
|
+
-- Strings and BigValue amounts require a Big currency.
|
|
1395
|
+
Cost: { Path: StatPathsType<T, true>, Amount: number | string | BigValue },
|
|
1330
1396
|
Category: string?,
|
|
1331
1397
|
ItemId: string,
|
|
1332
|
-
Grant: ((data:
|
|
1398
|
+
Grant: ((data: BuildGrantDataType<T, NodeFunctionNames>) -> ())?,
|
|
1333
1399
|
Meta: { [string]: any }?,
|
|
1334
1400
|
}
|
|
1335
1401
|
|
|
@@ -1500,15 +1566,15 @@ export type ScribeOptions<T, S = any> = {
|
|
|
1500
1566
|
StudioHook: boolean?, -- default false: the Studio debug hooks the Scribe Studio plugin reads
|
|
1501
1567
|
}
|
|
1502
1568
|
|
|
1503
|
-
export type ServerData<T, S = any> = BuildServerDataType<T, Player, S>
|
|
1569
|
+
export type ServerData<T, S = any> = BuildServerDataType<T, Player, S, NodeFunctionNames>
|
|
1504
1570
|
|
|
1505
|
-
export type ClientData<T, S = any> = BuildClientDataType<T, S>
|
|
1571
|
+
export type ClientData<T, S = any> = BuildClientDataType<T, S, NodeFunctionNames>
|
|
1506
1572
|
|
|
1507
1573
|
-- One player's typed accessor tree: the type of `Data[player]`, `Data.Get(player)` and
|
|
1508
1574
|
-- the client's `Data.Get()`. A plain alias because a type function cannot be invoked
|
|
1509
1575
|
-- across a module boundary: `Scribe.ValueType<T>` silently resolves to `any` rather than
|
|
1510
1576
|
-- erroring, so this is the only way a consumer can name the type.
|
|
1511
|
-
export type PlayerData<T> =
|
|
1577
|
+
export type PlayerData<T> = BuildValueType<T, NodeFunctionNames>
|
|
1512
1578
|
|
|
1513
1579
|
export type Bundle<T, S = any> = {
|
|
1514
1580
|
Server: ServerData<T, S>,
|