hackmud-script-manager 0.20.4-52a588b → 0.20.4-66e0e13
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/bin/hsm.js +144 -66
- package/env.d.ts +197 -192
- package/index.d.ts +3 -0
- package/index.js +1 -0
- package/package.json +3 -2
- package/processScript/index.d.ts +2 -2
- package/processScript/index.js +14 -10
- package/processScript/preprocess.js +2 -2
- package/processScript/transform.d.ts +3 -0
- package/processScript/transform.js +68 -30
- package/push.js +8 -5
- package/watch.js +24 -24
package/env.d.ts
CHANGED
@@ -1,9 +1,5 @@
|
|
1
|
-
type Replace<A, B> = Omit<A, keyof B> &
|
2
|
-
type ScriptSuccess<T = object> = { ok: true } & T
|
3
|
-
type ScriptFailure = { ok: false, msg?: string }
|
4
|
-
type ScriptResponse<T = object> = ScriptSuccess<T> | ScriptFailure
|
1
|
+
type Replace<A, B> = Omit<A, keyof B> & BigInt
|
5
2
|
type ErrorScripts = Record<string, () => ScriptFailure>
|
6
|
-
type Scriptor<TArgs extends any[] = any[]> = { name: string, call: (...args: TArgs) => unknown }
|
7
3
|
|
8
4
|
type Subscripts = Record<string, Record<string, (...args: any) => any>> & {
|
9
5
|
accts: ErrorScripts
|
@@ -21,15 +17,8 @@ type Subscripts = Record<string, Record<string, (...args: any) => any>> & {
|
|
21
17
|
users: ErrorScripts
|
22
18
|
}
|
23
19
|
|
24
|
-
interface PlayerFullsec {}
|
25
|
-
interface PlayerHighsec {}
|
26
|
-
interface PlayerMidsec {}
|
27
|
-
interface PlayerLowsec {}
|
28
|
-
interface PlayerNullsec {}
|
29
|
-
|
30
20
|
type UpgradeRarityString = "`0noob`" | "`1kiddie`" | "`2h4x0r`" | "`3h4rdc0r3`" | "`4|_|b3|2`" | "`531337`"
|
31
21
|
type UpgradeRarityNumber = 0 | 1 | 2 | 3 | 4 | 5
|
32
|
-
type UpgradeRarity = UpgradeRarityString | UpgradeRarityNumber
|
33
22
|
|
34
23
|
type UpgradeBase = {
|
35
24
|
name: string
|
@@ -765,7 +754,6 @@ type MongoQuerySelector<T extends MongoValue> = Partial<
|
|
765
754
|
>
|
766
755
|
|
767
756
|
type MongoQuery<T extends MongoObject> = { [K in keyof T]?: T[K] | MongoQuerySelector<T[K]> } & { _id?: MongoId }
|
768
|
-
type Projection = Record<string, boolean | 0 | 1>
|
769
757
|
|
770
758
|
type MongoUpdateOperators<T extends MongoObject> = Partial<{
|
771
759
|
/* Universal operators */
|
@@ -872,50 +860,6 @@ type SubscriptContext = Replace<CliContext, {
|
|
872
860
|
|
873
861
|
type ScriptorContext = Replace<CliContext, { /** Whether the script is being run as a scriptor. */ is_scriptor: true }>
|
874
862
|
type BrainContext = Replace<CliContext, { /** Whether the script is being run via a bot brain. */ is_brain: true }>
|
875
|
-
type Context = CliContext | SubscriptContext | ScriptorContext | BrainContext
|
876
|
-
|
877
|
-
/** Subscript space that can call FULLSEC scripts. */ declare const $fs: Fullsec
|
878
|
-
|
879
|
-
/** Subscript space that can call HIGHSEC and above scripts. Makes your script HIGHSEC (overrides FULLSEC). */
|
880
|
-
declare const $hs: Highsec
|
881
|
-
|
882
|
-
/** Subscript space that can call MIDSEC and above scripts. Makes your script MIDSEC (overrides higher security levels).
|
883
|
-
*/
|
884
|
-
declare const $ms: Midsec
|
885
|
-
|
886
|
-
/** Subscript space that can call LOWSEC and above scripts. Makes your script LOWSEC (overrides higher security levels).
|
887
|
-
*/
|
888
|
-
declare const $ls: Lowsec
|
889
|
-
|
890
|
-
/** Subscript space that can call any script. Makes your script NULLSEC (overrides higher security levels). */
|
891
|
-
declare const $ns: Nullsec
|
892
|
-
|
893
|
-
/** Subscript space that can call FULLSEC scripts. */ declare const $4s: typeof $fs
|
894
|
-
|
895
|
-
/** Subscript space that can call HIGHSEC and above scripts. Makes your script HIGHSEC (overrides FULLSEC). */
|
896
|
-
declare const $3s: typeof $hs
|
897
|
-
|
898
|
-
/** Subscript space that can call MIDSEC and above scripts. Makes your script MIDSEC (overrides higher security levels).
|
899
|
-
*/
|
900
|
-
declare const $2s: typeof $ms
|
901
|
-
|
902
|
-
/** Subscript space that can call LOWSEC and above scripts. Makes your script LOWSEC (overrides higher security levels).
|
903
|
-
*/
|
904
|
-
declare const $1s: typeof $ls
|
905
|
-
|
906
|
-
/** Subscript space that can call any script. Makes your script NULLSEC (overrides higher security levels). */
|
907
|
-
declare const $0s: typeof $ns
|
908
|
-
|
909
|
-
/** Subscript space that can call any script. Uses seclevel provided in comment before script (defaults to NULLSEC)
|
910
|
-
* @example
|
911
|
-
* // @seclevel MIDSEC
|
912
|
-
* // note, do NOT copy paste the above line because there is a zero-width space inserted between "@" and "s"
|
913
|
-
* export function script() {
|
914
|
-
* $s.foo.bar() // will be converted to #ms.foo.bar()
|
915
|
-
* } */
|
916
|
-
declare const $s: Nullsec
|
917
|
-
|
918
|
-
type ObjectId = { $oid: string }
|
919
863
|
|
920
864
|
// _id is always returned unless _id: false is passed
|
921
865
|
// when anyField: true is given, other fields (except _id) are omitted
|
@@ -935,142 +879,203 @@ type MongoProject<TDocument, TProjection> =
|
|
935
879
|
}
|
936
880
|
: { [k: string]: MongoValue } & { [K in keyof TDocument as K extends keyof TProjection ? never : K]: TDocument[K] }
|
937
881
|
|
938
|
-
|
939
|
-
/** Insert a document or documents into a collection.
|
940
|
-
* @param documents A document or array of documents to insert into the collection. */
|
941
|
-
i: <T extends MongoDocument>(documents: (T & { _id?: MongoId }) | (T & { _id?: MongoId })[]) =>
|
942
|
-
{ n: number, opTime: { t: number }, ok: 0 | 1 }[]
|
943
|
-
|
944
|
-
/** Remove documents from a collection.
|
945
|
-
* @param query Specifies deletion criteria using query operators. */
|
946
|
-
r: <T extends MongoDocument>(query: MongoQuery<T>) => { n: number, opTime: { t: number }, ok: 0 | 1 }[]
|
947
|
-
|
948
|
-
/** Find documents in a collection or view and returns a cursor to the selected documents.
|
949
|
-
* @param query Specifies deletion criteria using query operators.
|
950
|
-
* @param projection Specifies the fields to return in the documents that match the query filter. */
|
951
|
-
f: <
|
952
|
-
const TQuery extends MongoQueryObject & { _id?: MongoQueryId },
|
953
|
-
const TProjection extends { [k: string]: boolean | 0 | 1 } = {}
|
954
|
-
>(query: TQuery, projection?: TProjection) => Cursor<MongoProject<MongoQueryType<TQuery>, TProjection>>
|
955
|
-
|
956
|
-
/** Update existing documents in a collection.
|
957
|
-
* @param query Specifies deletion criteria using query operators.
|
958
|
-
* @param command The modifications to apply.
|
959
|
-
* {@link https://docs.mongodb.com/manual/reference/method/db.collection.update/#parameters} */
|
960
|
-
u: <T extends MongoDocument>(query: MongoQuery<T> | MongoQuery<T>[], command: MongoUpdateCommand<T>) =>
|
961
|
-
{ n: number, opTime: { t: number }, ok: 0 | 1, nModified: number }[]
|
962
|
-
|
963
|
-
/** Updates one document within the collection based on the filter.
|
964
|
-
* @param query Specifies deletion criteria using query operators.
|
965
|
-
* @param command The modifications to apply.
|
966
|
-
* {@link https://docs.mongodb.com/manual/reference/method/db.collection.update/#parameters} */
|
967
|
-
u1: <T extends MongoDocument>(query: MongoQuery<T> | MongoQuery<T>[], command: MongoUpdateCommand<T>) =>
|
968
|
-
{ n: number, ok: 0 | 1, opTime: { t: number }, nModified: number }[]
|
969
|
-
|
970
|
-
/** Update or insert document.
|
971
|
-
* Same as Update, but if no documents match the query, one document will be inserted based on the properties in
|
972
|
-
* both the query and the command.
|
973
|
-
* The `$setOnInsert` operator is useful to set defaults.
|
974
|
-
* @param query Specifies deletion criteria using query operators.
|
975
|
-
* @param command The modifications to apply.
|
976
|
-
* {@link https://docs.mongodb.com/manual/reference/method/db.collection.update/#parameters} */
|
977
|
-
us: <T extends MongoDocument>(query: MongoQuery<T> | MongoQuery<T>[], command: MongoUpdateCommand<T>) =>
|
978
|
-
{ n: number, ok: 0 | 1, opTime: { t: number }, nModified: number }[]
|
979
|
-
|
980
|
-
ObjectId: () => ObjectId
|
981
|
-
}
|
882
|
+
type DeepFreeze<T> = { readonly [P in keyof T]: DeepFreeze<T[P]> }
|
982
883
|
|
983
|
-
|
984
|
-
|
985
|
-
|
986
|
-
|
987
|
-
|
988
|
-
|
989
|
-
|
990
|
-
*
|
991
|
-
* `$D()` returns the first argument so `$D("Hello, World!") evaluates to `"Hello, World!"` as if the `$D` text wasn't
|
992
|
-
* there.
|
993
|
-
*
|
994
|
-
* `$D()`’d items are returned even if the script times out or errors. */
|
995
|
-
declare function $D<T>(args: T): T
|
996
|
-
|
997
|
-
/** Function Multi-Call Lock.
|
998
|
-
*
|
999
|
-
* This is used by escrow to ensure that it is only used once in script execution.
|
1000
|
-
*
|
1001
|
-
* The first time (per-script) `$FMCL` is encountered, it returns `undefined`, every other time it `return`s `true`.
|
1002
|
-
*
|
1003
|
-
* @example
|
1004
|
-
* if ($FMCL)
|
1005
|
-
* return { ok: false, msg: "This script can only be used once per script execution." }
|
1006
|
-
*
|
1007
|
-
* // all code here will only run once */
|
1008
|
-
declare const $FMCL: undefined | true
|
1009
|
-
|
1010
|
-
/** Per-script mutable "global" persistent object that is discarded at the end of top level script execution.
|
1011
|
-
*
|
1012
|
-
* `$G` persists between script calls until the end of the main script run making it useful for caching db entries when
|
1013
|
-
* your script is a subscript.
|
1014
|
-
* @example
|
1015
|
-
* if (!$G.dbCache)
|
1016
|
-
* $G.dbCache = $db.f({ whatever: true }).first() */
|
1017
|
-
declare const $G: Record<string | symbol, any>
|
1018
|
-
|
1019
|
-
/** This contains a JS timestamp (not Date) set immediately before your code begins running.
|
1020
|
-
* @example
|
1021
|
-
* $D(Date.now() - _START) // milliseconds left of run time
|
1022
|
-
*/
|
1023
|
-
declare const _START: number
|
1024
|
-
|
1025
|
-
/** This contains a JS timestamp (not Date) set immediately before your code begins running.
|
1026
|
-
* @example
|
1027
|
-
* $D(Date.now() - _ST) // milliseconds left of run time */
|
1028
|
-
declare const _ST: typeof _START
|
1029
|
-
|
1030
|
-
/** JavaScript timestamp for the end of the script run (`_START + _TIMEOUT`). */ declare const _END: number
|
1031
|
-
|
1032
|
-
/** The number of milliseconds a script can run for. Normally `5000` though it has been known to change. */
|
1033
|
-
declare const _TIMEOUT: number
|
1034
|
-
|
1035
|
-
/** The number of milliseconds a script can run for. Normally `5000` though it has been known to change. */
|
1036
|
-
declare const _TO: typeof _TIMEOUT
|
1037
|
-
|
1038
|
-
/** The source code of this script as a string. */ declare const _SOURCE: string
|
1039
|
-
/** A unix timestamp of the date this script was built. */ declare const _BUILD_DATE: number
|
1040
|
-
|
1041
|
-
/** The user this script has been uploaded to.
|
1042
|
-
*
|
1043
|
-
* Shorter alternative to `context.this_script.split(".")[0].
|
1044
|
-
*
|
1045
|
-
* In rare cases where it's not known at build time, it's `"UNKNOWN"`. */
|
1046
|
-
declare const _SCRIPT_USER: string
|
1047
|
-
|
1048
|
-
/** The name of this script excluding the user and `.`.
|
1049
|
-
*
|
1050
|
-
* e.g. in the script `foo.bar`, `_SCRIPT_NAME` is `bar`.
|
1051
|
-
*
|
1052
|
-
* Shorter alternative to `context.this_script.split(".")[1].
|
1053
|
-
*
|
1054
|
-
* In rare cases where it's not known at build time, it's `"UNKNOWN"`. */
|
1055
|
-
declare const _SCRIPT_NAME: string
|
1056
|
-
|
1057
|
-
/** The full name of this script equivilent to `context.this_script` but should use less characters.
|
1058
|
-
*
|
1059
|
-
* In rare cases where it's not known at build time, it's `"UNKNOWN"`. */
|
1060
|
-
declare const _FULL_SCRIPT_NAME: string
|
1061
|
-
|
1062
|
-
/** The seclevel of this script as a number.
|
1063
|
-
*
|
1064
|
-
* In rare cases where it's not known at build time, it's `-1`. */
|
1065
|
-
declare const _SECLEVEL: -1 | 0 | 1 | 2 | 3 | 4
|
884
|
+
declare global {
|
885
|
+
type ScriptSuccess<T = unknown> = { ok: true } & T
|
886
|
+
type ScriptFailure = { ok: false, msg?: string }
|
887
|
+
type ScriptResponse<T = unknown> = ScriptSuccess<T> | ScriptFailure
|
888
|
+
type Scriptor<TArgs extends any[] = any[]> = { name: string, call: (...args: TArgs) => unknown }
|
889
|
+
type Context = CliContext | SubscriptContext | ScriptorContext | BrainContext
|
890
|
+
type ObjectId = { $oid: string }
|
1066
891
|
|
1067
|
-
|
892
|
+
interface PlayerFullsec {}
|
893
|
+
interface PlayerHighsec {}
|
894
|
+
interface PlayerMidsec {}
|
895
|
+
interface PlayerLowsec {}
|
896
|
+
interface PlayerNullsec {}
|
1068
897
|
|
1069
|
-
/**
|
1070
|
-
|
1071
|
-
|
1072
|
-
|
1073
|
-
|
1074
|
-
|
898
|
+
/** Subscript space that can call FULLSEC scripts. */ const $fs: Fullsec
|
899
|
+
|
900
|
+
/** Subscript space that can call HIGHSEC and above scripts. Makes your script HIGHSEC (overrides FULLSEC). */
|
901
|
+
const $hs: Highsec
|
902
|
+
|
903
|
+
/** Subscript space that can call MIDSEC and above scripts. Makes your script MIDSEC (overrides higher security levels).
|
904
|
+
*/
|
905
|
+
const $ms: Midsec
|
906
|
+
|
907
|
+
/** Subscript space that can call LOWSEC and above scripts. Makes your script LOWSEC (overrides higher security levels).
|
908
|
+
*/
|
909
|
+
const $ls: Lowsec
|
910
|
+
|
911
|
+
/** Subscript space that can call any script. Makes your script NULLSEC (overrides higher security levels). */
|
912
|
+
const $ns: Nullsec
|
913
|
+
|
914
|
+
/** Subscript space that can call FULLSEC scripts. */ const $4s: typeof $fs
|
915
|
+
|
916
|
+
/** Subscript space that can call HIGHSEC and above scripts. Makes your script HIGHSEC (overrides FULLSEC). */
|
917
|
+
const $3s: typeof $hs
|
918
|
+
|
919
|
+
/** Subscript space that can call MIDSEC and above scripts. Makes your script MIDSEC (overrides higher security levels).
|
920
|
+
*/
|
921
|
+
const $2s: typeof $ms
|
922
|
+
|
923
|
+
/** Subscript space that can call LOWSEC and above scripts. Makes your script LOWSEC (overrides higher security levels).
|
924
|
+
*/
|
925
|
+
const $1s: typeof $ls
|
926
|
+
|
927
|
+
/** Subscript space that can call any script. Makes your script NULLSEC (overrides higher security levels). */
|
928
|
+
const $0s: typeof $ns
|
929
|
+
|
930
|
+
/** Subscript space that can call any script. Uses seclevel provided in comment before script (defaults to NULLSEC)
|
931
|
+
* @example
|
932
|
+
* // @seclevel MIDSEC
|
933
|
+
* // note, do NOT copy paste the above line because there is a zero-width space inserted between "@" and "s"
|
934
|
+
* export function script() {
|
935
|
+
* $s.foo.bar() // will be converted to #ms.foo.bar()
|
936
|
+
* } */
|
937
|
+
const $s: Nullsec
|
938
|
+
|
939
|
+
const $db: {
|
940
|
+
/** Insert a document or documents into a collection.
|
941
|
+
* @param documents A document or array of documents to insert into the collection. */
|
942
|
+
i: <T extends MongoDocument>(documents: (T & { _id?: MongoId }) | (T & { _id?: MongoId })[]) =>
|
943
|
+
{ n: number, opTime: { t: number }, ok: 0 | 1 }[]
|
944
|
+
|
945
|
+
/** Remove documents from a collection.
|
946
|
+
* @param query Specifies deletion criteria using query operators. */
|
947
|
+
r: <T extends MongoDocument>(query: MongoQuery<T>) => { n: number, opTime: { t: number }, ok: 0 | 1 }[]
|
948
|
+
|
949
|
+
/** Find documents in a collection or view and returns a cursor to the selected documents.
|
950
|
+
* @param query Specifies deletion criteria using query operators.
|
951
|
+
* @param projection Specifies the fields to return in the documents that match the query filter. */
|
952
|
+
f: <
|
953
|
+
const TQuery extends MongoQueryObject & { _id?: MongoQueryId },
|
954
|
+
const TProjection extends { [k: string]: boolean | 0 | 1 } = {}
|
955
|
+
>(query: TQuery, projection?: TProjection) => Cursor<MongoProject<MongoQueryType<TQuery>, TProjection>>
|
956
|
+
|
957
|
+
/** Update existing documents in a collection.
|
958
|
+
* @param query Specifies deletion criteria using query operators.
|
959
|
+
* @param command The modifications to apply.
|
960
|
+
* {@link https://docs.mongodb.com/manual/reference/method/db.collection.update/#parameters} */
|
961
|
+
u: <T extends MongoDocument>(query: MongoQuery<T> | MongoQuery<T>[], command: MongoUpdateCommand<T>) =>
|
962
|
+
{ n: number, opTime: { t: number }, ok: 0 | 1, nModified: number }[]
|
963
|
+
|
964
|
+
/** Updates one document within the collection based on the filter.
|
965
|
+
* @param query Specifies deletion criteria using query operators.
|
966
|
+
* @param command The modifications to apply.
|
967
|
+
* {@link https://docs.mongodb.com/manual/reference/method/db.collection.update/#parameters} */
|
968
|
+
u1: <T extends MongoDocument>(query: MongoQuery<T> | MongoQuery<T>[], command: MongoUpdateCommand<T>) =>
|
969
|
+
{ n: number, ok: 0 | 1, opTime: { t: number }, nModified: number }[]
|
970
|
+
|
971
|
+
/** Update or insert document.
|
972
|
+
* Same as Update, but if no documents match the query, one document will be inserted based on the properties in
|
973
|
+
* both the query and the command.
|
974
|
+
* The `$setOnInsert` operator is useful to set defaults.
|
975
|
+
* @param query Specifies deletion criteria using query operators.
|
976
|
+
* @param command The modifications to apply.
|
977
|
+
* {@link https://docs.mongodb.com/manual/reference/method/db.collection.update/#parameters} */
|
978
|
+
us: <T extends MongoDocument>(query: MongoQuery<T> | MongoQuery<T>[], command: MongoUpdateCommand<T>) =>
|
979
|
+
{ n: number, ok: 0 | 1, opTime: { t: number }, nModified: number }[]
|
980
|
+
|
981
|
+
ObjectId: () => ObjectId
|
982
|
+
}
|
983
|
+
|
984
|
+
/** Debug Log.
|
985
|
+
*
|
986
|
+
* If `$D()` is called in a script you own, the `return` value of the top level script is suppressed and instead an
|
987
|
+
* array of every `$D()`’d entry is printed.
|
988
|
+
* This lets you use `$D()` like `console.log()`.
|
989
|
+
*
|
990
|
+
* `$D()` in scripts not owned by you are not shown but the `return` value always is.
|
991
|
+
*
|
992
|
+
* `$D()` returns the first argument so `$D("Hello, World!") evaluates to `"Hello, World!"` as if the `$D` text wasn't
|
993
|
+
* there.
|
994
|
+
*
|
995
|
+
* `$D()`’d items are returned even if the script times out or errors. */
|
996
|
+
function $D<T>(args: T): T
|
997
|
+
|
998
|
+
/** Function Multi-Call Lock.
|
999
|
+
*
|
1000
|
+
* This is used by escrow to ensure that it is only used once in script execution.
|
1001
|
+
*
|
1002
|
+
* The first time (per-script) `$FMCL` is encountered, it returns `undefined`, every other time it `return`s `true`.
|
1003
|
+
*
|
1004
|
+
* @example
|
1005
|
+
* if ($FMCL)
|
1006
|
+
* return { ok: false, msg: "This script can only be used once per script execution." }
|
1007
|
+
*
|
1008
|
+
* // all code here will only run once */
|
1009
|
+
const $FMCL: undefined | true
|
1010
|
+
|
1011
|
+
/** Per-script mutable "global" persistent object that is discarded at the end of top level script execution.
|
1012
|
+
*
|
1013
|
+
* `$G` persists between script calls until the end of the main script run making it useful for caching db entries when
|
1014
|
+
* your script is a subscript.
|
1015
|
+
* @example
|
1016
|
+
* if (!$G.dbCache)
|
1017
|
+
* $G.dbCache = $db.f({ whatever: true }).first() */
|
1018
|
+
const $G: Record<string | symbol, any>
|
1019
|
+
|
1020
|
+
/** This contains a JS timestamp (not Date) set immediately before your code begins running.
|
1021
|
+
* @example
|
1022
|
+
* $D(Date.now() - _START) // milliseconds left of run time
|
1023
|
+
*/
|
1024
|
+
const _START: number
|
1025
|
+
|
1026
|
+
/** This contains a JS timestamp (not Date) set immediately before your code begins running.
|
1027
|
+
* @example
|
1028
|
+
* $D(Date.now() - _ST) // milliseconds left of run time */
|
1029
|
+
const _ST: typeof _START
|
1030
|
+
|
1031
|
+
/** JavaScript timestamp for the end of the script run (`_START + _TIMEOUT`). */ const _END: number
|
1032
|
+
|
1033
|
+
/** The number of milliseconds a script can run for. Normally `5000` though it has been known to change. */
|
1034
|
+
const _TIMEOUT: number
|
1035
|
+
|
1036
|
+
/** The number of milliseconds a script can run for. Normally `5000` though it has been known to change. */
|
1037
|
+
const _TO: typeof _TIMEOUT
|
1038
|
+
|
1039
|
+
/** The source code of this script as a string. */ const _SOURCE: string
|
1040
|
+
/** A unix timestamp of the date this script was built. */ const _BUILD_DATE: number
|
1041
|
+
|
1042
|
+
/** The user this script has been uploaded to.
|
1043
|
+
*
|
1044
|
+
* Shorter alternative to `context.this_script.split(".")[0].
|
1045
|
+
*
|
1046
|
+
* In rare cases where it's not known at build time, it's `"UNKNOWN"`. */
|
1047
|
+
const _SCRIPT_USER: string
|
1048
|
+
|
1049
|
+
/** @deprecated Use `_SCRIPT_SUBNAME` instead. */
|
1050
|
+
const _SCRIPT_NAME: string
|
1051
|
+
|
1052
|
+
/** The name of this script excluding the user and `.`.
|
1053
|
+
*
|
1054
|
+
* e.g. in the script `foo.bar`, `_SCRIPT_NAME` is `bar`.
|
1055
|
+
*
|
1056
|
+
* Shorter alternative to `context.this_script.split(".")[1].
|
1057
|
+
*
|
1058
|
+
* In rare cases where it's not known at build time, it's `"UNKNOWN"`. */
|
1059
|
+
const _SCRIPT_SUBNAME: string
|
1060
|
+
|
1061
|
+
/** The full name of this script equivilent to `context.this_script` but should use less characters.
|
1062
|
+
*
|
1063
|
+
* In rare cases where it's not known at build time, it's `"UNKNOWN"`. */
|
1064
|
+
const _FULL_SCRIPT_NAME: string
|
1065
|
+
|
1066
|
+
/** The seclevel of this script as a number.
|
1067
|
+
*
|
1068
|
+
* In rare cases where it's not known at build time, it's `-1`. */
|
1069
|
+
const _SECLEVEL: -1 | 0 | 1 | 2 | 3 | 4
|
1070
|
+
|
1071
|
+
/** Recursively
|
1072
|
+
* [`Object.freeze()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/freeze)
|
1073
|
+
* an object and its properties' objects and its properties' objects and so on.
|
1074
|
+
*
|
1075
|
+
* [Official Hackmud Wiki](https://wiki.hackmud.com/scripting/extensions/deep_freeze) */
|
1076
|
+
const DEEP_FREEZE: <T>(value: T) => DeepFreeze<T>
|
1077
|
+
|
1078
|
+
const _RUN_ID: string
|
1079
|
+
}
|
1075
1080
|
|
1076
|
-
|
1081
|
+
export {}
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
@@ -27,6 +27,7 @@ import "@babel/plugin-transform-private-property-in-object"
|
|
27
27
|
import "@babel/plugin-transform-unicode-sets-regex"
|
28
28
|
import "@babel/traverse"
|
29
29
|
import "@babel/types"
|
30
|
+
import "@rollup/plugin-alias"
|
30
31
|
import "@rollup/plugin-babel"
|
31
32
|
import "@rollup/plugin-commonjs"
|
32
33
|
import "@rollup/plugin-json"
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "hackmud-script-manager",
|
3
|
-
"version": "0.20.4-
|
3
|
+
"version": "0.20.4-66e0e13",
|
4
4
|
"description": "Script manager for game hackmud, with minification, TypeScript support, and player script type definition generation.",
|
5
5
|
"keywords": [
|
6
6
|
"api",
|
@@ -59,6 +59,7 @@
|
|
59
59
|
"@babel/traverse": "^7.25.9",
|
60
60
|
"@babel/types": "^7.26.0",
|
61
61
|
"@bloomberg/record-tuple-polyfill": "^0.0.4",
|
62
|
+
"@rollup/plugin-alias": "^5.1.1",
|
62
63
|
"@rollup/plugin-babel": "^6.0.4",
|
63
64
|
"@rollup/plugin-commonjs": "^28.0.1",
|
64
65
|
"@rollup/plugin-json": "^6.1.0",
|
@@ -86,6 +87,6 @@
|
|
86
87
|
"hsm": "bin/hsm.js"
|
87
88
|
},
|
88
89
|
"engines": {
|
89
|
-
"node": "^18 ||
|
90
|
+
"node": "^18 || >=20"
|
90
91
|
}
|
91
92
|
}
|
package/processScript/index.d.ts
CHANGED
@@ -16,16 +16,16 @@ export type ProcessOptions = LaxPartial<{
|
|
16
16
|
* when left unset or set to `undefined`, automatically uses or doesn't use quine cheats based on character count
|
17
17
|
*/
|
18
18
|
forceQuineCheats: boolean;
|
19
|
+
rootFolderPath: string;
|
19
20
|
}> & {
|
20
21
|
scriptName: string | true;
|
21
22
|
};
|
22
23
|
/** Minifies a given script
|
23
24
|
* @param code JavaScript or TypeScript code
|
24
25
|
* @param options {@link ProcessOptions details} */
|
25
|
-
export declare function processScript(code: string, { minify: shouldMinify, uniqueId, scriptUser, scriptName, filePath, mangleNames, forceQuineCheats }: ProcessOptions): Promise<{
|
26
|
+
export declare function processScript(code: string, { minify: shouldMinify, uniqueId, scriptUser, scriptName, filePath, mangleNames, forceQuineCheats, rootFolderPath }: ProcessOptions): Promise<{
|
26
27
|
script: string;
|
27
28
|
warnings: {
|
28
29
|
message: string;
|
29
|
-
line: number;
|
30
30
|
}[];
|
31
31
|
}>;
|
package/processScript/index.js
CHANGED
@@ -17,12 +17,13 @@ import babelPluginTransformPrivatePropertyInObject from "@babel/plugin-transform
|
|
17
17
|
import babelPluginTransformUnicodeSetsRegex from "@babel/plugin-transform-unicode-sets-regex"
|
18
18
|
import babelTraverse from "@babel/traverse"
|
19
19
|
import t from "@babel/types"
|
20
|
+
import rollupPluginAlias from "@rollup/plugin-alias"
|
20
21
|
import { babel } from "@rollup/plugin-babel"
|
21
22
|
import rollupPluginCommonJS from "@rollup/plugin-commonjs"
|
22
23
|
import rollupPluginJSON from "@rollup/plugin-json"
|
23
24
|
import rollupPluginNodeResolve from "@rollup/plugin-node-resolve"
|
24
25
|
import { assert } from "@samual/lib/assert"
|
25
|
-
import {
|
26
|
+
import { relative } from "path"
|
26
27
|
import prettier from "prettier"
|
27
28
|
import { rollup } from "rollup"
|
28
29
|
import { supportedExtensions } from "../constants.js"
|
@@ -51,10 +52,11 @@ async function processScript(
|
|
51
52
|
scriptName,
|
52
53
|
filePath,
|
53
54
|
mangleNames = !1,
|
54
|
-
forceQuineCheats
|
55
|
+
forceQuineCheats,
|
56
|
+
rootFolderPath
|
55
57
|
}
|
56
58
|
) {
|
57
|
-
assert(/^\w{11}$/.exec(uniqueId), "src/processScript/index.ts:
|
59
|
+
assert(/^\w{11}$/.exec(uniqueId), "src/processScript/index.ts:81:36")
|
58
60
|
const sourceCode = code
|
59
61
|
let autocomplete, statedSeclevel
|
60
62
|
const autocompleteMatch = /^function\s*\(.+\/\/(?<autocomplete>.+)/.exec(code)
|
@@ -115,7 +117,7 @@ async function processScript(
|
|
115
117
|
}
|
116
118
|
}
|
117
119
|
}
|
118
|
-
assert(/^\w{11}$/.exec(uniqueId), "src/processScript/index.ts:
|
120
|
+
assert(/^\w{11}$/.exec(uniqueId), "src/processScript/index.ts:162:36")
|
119
121
|
const plugins = [
|
120
122
|
[babelPluginProposalDecorators.default, { decoratorsBeforeExport: !0 }],
|
121
123
|
[babelPluginTransformClassProperties.default],
|
@@ -135,7 +137,7 @@ async function processScript(
|
|
135
137
|
]
|
136
138
|
let filePathResolved
|
137
139
|
if (filePath) {
|
138
|
-
filePathResolved =
|
140
|
+
filePathResolved = relative(".", filePath)
|
139
141
|
if (filePath.endsWith(".ts"))
|
140
142
|
plugins.push([
|
141
143
|
(await import("@babel/plugin-transform-typescript")).default,
|
@@ -201,6 +203,7 @@ async function processScript(
|
|
201
203
|
[babelPluginProposalRecordAndTuple.default, { syntaxType: "hash", importPolyfill: !0 }]
|
202
204
|
)
|
203
205
|
}
|
206
|
+
console.debug("src/processScript/index.ts:256:16", supportedExtensions)
|
204
207
|
const bundle = await rollup({
|
205
208
|
input: filePathResolved,
|
206
209
|
plugins: [
|
@@ -228,13 +231,14 @@ async function processScript(
|
|
228
231
|
},
|
229
232
|
babel({ babelHelpers: "bundled", plugins, configFile: !1, extensions: supportedExtensions }),
|
230
233
|
rollupPluginCommonJS(),
|
231
|
-
rollupPluginNodeResolve({ extensions: supportedExtensions })
|
234
|
+
rollupPluginNodeResolve({ extensions: supportedExtensions }),
|
235
|
+
!!rootFolderPath && rollupPluginAlias({ entries: [{ find: /^\//, replacement: rootFolderPath + "/" }] })
|
232
236
|
],
|
233
237
|
treeshake: { moduleSideEffects: !1 }
|
234
238
|
}),
|
235
239
|
seclevelNames = ["NULLSEC", "LOWSEC", "MIDSEC", "HIGHSEC", "FULLSEC"]
|
236
240
|
code = (await bundle.generate({})).output[0].code
|
237
|
-
const { file, seclevel } = transform(parse(code, { sourceType: "module" }), sourceCode, {
|
241
|
+
const { file, seclevel, warnings } = transform(parse(code, { sourceType: "module" }), sourceCode, {
|
238
242
|
uniqueId,
|
239
243
|
scriptUser,
|
240
244
|
scriptName
|
@@ -249,7 +253,7 @@ async function processScript(
|
|
249
253
|
traverse(file, {
|
250
254
|
MemberExpression({ node: memberExpression }) {
|
251
255
|
if (!memberExpression.computed) {
|
252
|
-
assert("Identifier" == memberExpression.property.type, "src/processScript/index.ts:
|
256
|
+
assert("Identifier" == memberExpression.property.type, "src/processScript/index.ts:328:60")
|
253
257
|
if ("prototype" == memberExpression.property.name) {
|
254
258
|
memberExpression.computed = !0
|
255
259
|
memberExpression.property = t.stringLiteral("prototype")
|
@@ -279,7 +283,7 @@ async function processScript(
|
|
279
283
|
break
|
280
284
|
case "ObjectPattern":
|
281
285
|
for (const property of lValue.properties) {
|
282
|
-
assert("ObjectProperty" == property.type, "src/processScript/index.ts:
|
286
|
+
assert("ObjectProperty" == property.type, "src/processScript/index.ts:358:51")
|
283
287
|
renameVariables(property.value)
|
284
288
|
}
|
285
289
|
break
|
@@ -328,6 +332,6 @@ async function processScript(
|
|
328
332
|
throw Error(
|
329
333
|
'you found a weird edge case where I wasn\'t able to replace illegal strings like "SC$", please report thx'
|
330
334
|
)
|
331
|
-
return { script: code, warnings
|
335
|
+
return { script: code, warnings }
|
332
336
|
}
|
333
337
|
export { minify, postprocess, preprocess, processScript, transform }
|
@@ -8,7 +8,7 @@ import { resolve } from "import-meta-resolve"
|
|
8
8
|
const { default: traverse } = babelTraverse,
|
9
9
|
{ default: generate } = babelGenerator
|
10
10
|
async function preprocess(code, { uniqueId = "00000000000" } = {}) {
|
11
|
-
assert(/^\w{11}$/.test(uniqueId), "src/processScript/preprocess.ts:
|
11
|
+
assert(/^\w{11}$/.test(uniqueId), "src/processScript/preprocess.ts:23:36")
|
12
12
|
const sourceCode = code
|
13
13
|
let lengthBefore, file, program
|
14
14
|
do {
|
@@ -47,7 +47,7 @@ async function preprocess(code, { uniqueId = "00000000000" } = {}) {
|
|
47
47
|
})
|
48
48
|
break
|
49
49
|
} catch (error_) {
|
50
|
-
assert(error_ instanceof SyntaxError, "src/processScript/preprocess.ts:
|
50
|
+
assert(error_ instanceof SyntaxError, "src/processScript/preprocess.ts:67:42")
|
51
51
|
error = error_
|
52
52
|
}
|
53
53
|
if ("BABEL_PARSER_SYNTAX_ERROR" != error.code || "PrivateInExpectedIn" != error.reasonCode) {
|
@@ -16,4 +16,7 @@ export type TransformOptions = LaxPartial<{
|
|
16
16
|
export declare function transform(file: File, sourceCode: string, { uniqueId, scriptUser, scriptName, seclevel }: TransformOptions): {
|
17
17
|
file: File;
|
18
18
|
seclevel: number;
|
19
|
+
warnings: {
|
20
|
+
message: string;
|
21
|
+
}[];
|
19
22
|
};
|