toilscript 0.1.38 → 0.1.41
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/dist/cli.generated.d.ts +233 -3
- package/dist/cli.js +15 -11
- package/dist/cli.js.map +3 -3
- package/dist/importmap.json +2 -2
- package/dist/toilscript.generated.d.ts +233 -3
- package/dist/toilscript.js +205 -194
- package/dist/toilscript.js.map +3 -3
- package/dist/web.js +3 -3
- package/package.json +5 -2
- package/std/assembly/bindings/toildb.ts +6 -4
- package/std/assembly/toildb.ts +4 -2
- package/std/assembly/toilscript.d.ts +108 -0
package/dist/cli.generated.d.ts
CHANGED
|
@@ -2946,6 +2946,94 @@ declare module "types:toilscript/src/dbcatalog" {
|
|
|
2946
2946
|
*/
|
|
2947
2947
|
export function buildToilDbCatalog(program: Program): Uint8Array | null;
|
|
2948
2948
|
export function buildToilDbTypes(program: Program): Uint8Array | null;
|
|
2949
|
+
/** Build the `toildb.route_kinds` section bytes, or `null` when no route needs
|
|
2950
|
+
* an extra runtime DB-policy clamp. The edge already derives the default kind
|
|
2951
|
+
* from the trusted HTTP method. This section only carries the stricter source
|
|
2952
|
+
* signal that the method clamp cannot infer: mutating-method routes explicitly
|
|
2953
|
+
* declared `@query`.
|
|
2954
|
+
*
|
|
2955
|
+
* Wire format (LE):
|
|
2956
|
+
* u16 format_version = 1
|
|
2957
|
+
* u16 n_routes
|
|
2958
|
+
* per route:
|
|
2959
|
+
* u8 method (same values as runtime Methods / request envelope)
|
|
2960
|
+
* u8 function_kind (0 = Query)
|
|
2961
|
+
* str route_pattern (same normalized pattern emitted into __toilMatch)
|
|
2962
|
+
*/
|
|
2963
|
+
export function buildToilDbRouteKinds(program: Program): Uint8Array | null;
|
|
2964
|
+
/** Build the `toilstream.catalog` section bytes, or `null` if the program
|
|
2965
|
+
* declares no `@stream` class. Per Part 5 (LE):
|
|
2966
|
+
*
|
|
2967
|
+
* u16 format_version = 1
|
|
2968
|
+
* u16 n_streams
|
|
2969
|
+
* per stream:
|
|
2970
|
+
* str name
|
|
2971
|
+
* str route
|
|
2972
|
+
* u8 hook_presence_bitmask (bit0 connect..bit3 disconnect)
|
|
2973
|
+
* u8 declared_scope (0 regional/L2, 1 continental/L3)
|
|
2974
|
+
* u8 message_mode (0 raw, 1 @data-typed)
|
|
2975
|
+
* u32 max_frame_bytes (0 = use plan default)
|
|
2976
|
+
* u32 ingress_ring_bytes (0 = host chooses)
|
|
2977
|
+
* u32 message_value_data_id (fnv1a(typeName); 0 when raw)
|
|
2978
|
+
* u32 message_schema_version (recursive layoutHash; 0 when raw)
|
|
2979
|
+
* u16 stream_index (0-based position in this array)
|
|
2980
|
+
*/
|
|
2981
|
+
export function buildToilStreamCatalog(program: Program): Uint8Array | null;
|
|
2982
|
+
/** Build the `toildaemon.catalog` section bytes, or `null` if the program
|
|
2983
|
+
* declares no `@daemon` class. Per Part 5 (LE):
|
|
2984
|
+
*
|
|
2985
|
+
* u16 format_version = 1
|
|
2986
|
+
* u8 has_daemon
|
|
2987
|
+
* u16 n_scheduled
|
|
2988
|
+
* per task:
|
|
2989
|
+
* str name
|
|
2990
|
+
* u16 task_index
|
|
2991
|
+
* u8 schedule_kind (0 interval, 1 cron)
|
|
2992
|
+
* u64 interval_ms
|
|
2993
|
+
* u64 cron_minute_mask (bits 0..59)
|
|
2994
|
+
* u32 cron_hour_mask
|
|
2995
|
+
* u32 cron_dom_mask
|
|
2996
|
+
* u16 cron_month_mask
|
|
2997
|
+
* u8 cron_dow_mask
|
|
2998
|
+
* u8 overlap_policy (0 default)
|
|
2999
|
+
* u8 catchup_policy (0 default)
|
|
3000
|
+
* u64 gas_hint
|
|
3001
|
+
*
|
|
3002
|
+
* Parses each `@scheduled(spec)` argument; fires diagnostics 9010/9011 for a
|
|
3003
|
+
* missing/non-string arg or an unparseable spec.
|
|
3004
|
+
*/
|
|
3005
|
+
export function buildToilDaemonCatalog(program: Program): Uint8Array | null;
|
|
3006
|
+
/** Build the `toil.surface` section bytes (always emitted per artifact). Per
|
|
3007
|
+
* Part 5 (LE):
|
|
3008
|
+
*
|
|
3009
|
+
* u16 format_version = 1
|
|
3010
|
+
* u8 target_mode (0 hot, 1 cold)
|
|
3011
|
+
* u8 reserved0 (0)
|
|
3012
|
+
* u32 surface_flags (bit0 rest..bit5 render)
|
|
3013
|
+
* u16 abi_version
|
|
3014
|
+
* str build_id
|
|
3015
|
+
* u32 fingerprint
|
|
3016
|
+
* u32 data_coherence_hash
|
|
3017
|
+
* u32 pair_coherence_hash
|
|
3018
|
+
*
|
|
3019
|
+
* `targetMode` "cold" -> 1; "hot" or null (legacy single artifact, treated as
|
|
3020
|
+
* hot per Part 5) -> 0. The two coherence hashes use the SAME `layoutHash` /
|
|
3021
|
+
* `recursionTypeMap` machinery as the toildb catalog, so a hot pass and a cold
|
|
3022
|
+
* pass over the same sources compute identical `data_coherence_hash` and
|
|
3023
|
+
* `pair_coherence_hash` independently (doc 02 AN-4). `build_id` is empty and
|
|
3024
|
+
* `abi_version` is 1 in this increment (the toiljs build-identity plumbing and
|
|
3025
|
+
* the export-name fingerprint component land with the codegen increment).
|
|
3026
|
+
*
|
|
3027
|
+
* Returns `null` (no section) for a bare AssemblyScript module compiled in
|
|
3028
|
+
* LEGACY mode (`targetMode == null`) that declares NO Toil surface at all
|
|
3029
|
+
* (`@rest`/`@stream`/`@daemon`/`@scheduled`/`@database`/`@data`), so an ordinary
|
|
3030
|
+
* AS compile stays byte-identical (the same gating philosophy as the existing
|
|
3031
|
+
* `toildb.catalog`, which is absent without `@database`). Part 5 / doc 02 AN-2
|
|
3032
|
+
* requires the section in every TOIL artifact (including a legacy single-artifact
|
|
3033
|
+
* toil build, which always carries a toil surface); a non-toil module is not a
|
|
3034
|
+
* toil artifact. An explicit `--targetMode hot|cold` always emits the section.
|
|
3035
|
+
*/
|
|
3036
|
+
export function buildToilSurface(program: Program, targetMode: string | null): Uint8Array | null;
|
|
2949
3037
|
}
|
|
2950
3038
|
declare module "types:toilscript/src/parser" {
|
|
2951
3039
|
/**
|
|
@@ -2982,6 +3070,10 @@ declare module "types:toilscript/src/parser" {
|
|
|
2982
3070
|
dependees: Map<string, Dependee>;
|
|
2983
3071
|
/** Normalized paths whose `@rest` runtime import has already been injected. */
|
|
2984
3072
|
restImportedSources: Set<string>;
|
|
3073
|
+
/** Normalized paths whose `@stream` module-level registry + the single
|
|
3074
|
+
* `stream_dispatch` export have already been emitted (a project may declare
|
|
3075
|
+
* several `@stream` classes, but the export is emitted exactly once). */
|
|
3076
|
+
streamExportedSources: Set<string>;
|
|
2985
3077
|
/** Monotonic id handed to each `@ratelimit` route so the edge can key one
|
|
2986
3078
|
* shared limiter per route. Program-wide (one Parser per program), assigned
|
|
2987
3079
|
* deterministically in route declaration order. */
|
|
@@ -3103,6 +3195,99 @@ declare module "types:toilscript/src/parser" {
|
|
|
3103
3195
|
* return; plus a module-level self-registration into the runtime `Rest` router.
|
|
3104
3196
|
*/
|
|
3105
3197
|
private injectRestController;
|
|
3198
|
+
/**
|
|
3199
|
+
* Synthesize the cold-artifact daemon entry for a `@daemon` class (spec 03
|
|
3200
|
+
* sections 5.2 / 5.6 / 5.7, Reconciliation Part 2 cold exports). Mirrors
|
|
3201
|
+
* `injectRestController`: it scans the class methods once (same source-order
|
|
3202
|
+
* walk the `toildaemon.catalog` builder uses, so `task_index` <-> dispatch
|
|
3203
|
+
* index stay in lockstep), synthesizes a `__tick(task)` dispatcher onto the
|
|
3204
|
+
* class, and emits the two canonical cold module-level exports:
|
|
3205
|
+
*
|
|
3206
|
+
* `daemon_start(): i32` - runs once at cold-box boot; instantiates the
|
|
3207
|
+
* `@daemon` class, holds the single box-lifetime
|
|
3208
|
+
* instance, runs the optional `onStart()`, and
|
|
3209
|
+
* returns 0 (negative = Part 3 error bridge).
|
|
3210
|
+
* `scheduled_tick(task_id: i32): i64` - dispatches `instance.__tick(task_id)`
|
|
3211
|
+
* by switching on the catalog `task_index`;
|
|
3212
|
+
* returns 0 (negative = Part 3 error bridge).
|
|
3213
|
+
*
|
|
3214
|
+
* Unlike `injectRestController`, the exports are self-contained (they do NOT
|
|
3215
|
+
* route through an external runtime `Daemon` registry import). The injected
|
|
3216
|
+
* `register(...)` in `injectRestController` is pruned when nothing reachable
|
|
3217
|
+
* references it, but a top-level EXPORT that referenced an unresolved runtime
|
|
3218
|
+
* import would be a hard compile error (TS6054), so the host-called exports
|
|
3219
|
+
* are synthesized as plain top-level `export function`s and keep the one
|
|
3220
|
+
* box-lifetime instance in a module-level singleton (doc 03 D1 / section 2:
|
|
3221
|
+
* per-domain state lives in instance fields for the box lifetime).
|
|
3222
|
+
*
|
|
3223
|
+
* Fires diagnostic 9012 for a `@scheduled` method with a non-empty parameter
|
|
3224
|
+
* list or a non-void return type, and the 9008 warning for a `@daemon` class
|
|
3225
|
+
* with zero `@scheduled` tasks (a daemon may legitimately run only `onStart`).
|
|
3226
|
+
*/
|
|
3227
|
+
private injectDaemonHandler;
|
|
3228
|
+
/**
|
|
3229
|
+
* Synthesize the hot-artifact stream entry for a `@stream` class (spec 03
|
|
3230
|
+
* sections 5.1 / 5.4, Reconciliation Part 2 hot exports). Mirrors
|
|
3231
|
+
* `injectDaemonHandler`: it scans the class methods once (same source-order
|
|
3232
|
+
* walk the `toilstream.catalog` builder + `streamHookMask` use), classifies
|
|
3233
|
+
* each by lifecycle-hook kind (`@connect`/`@message`/`@close`/`@disconnect`),
|
|
3234
|
+
* synthesizes a `__streamDispatch(event_kind)` dispatcher onto the class, and
|
|
3235
|
+
* emits the canonical hot module-level export:
|
|
3236
|
+
*
|
|
3237
|
+
* `stream_dispatch(event_kind: i32, stream_id_lo: i32, stream_id_hi: i32): i64`
|
|
3238
|
+
* - the per-connection event entry, emitted EXACTLY ONCE per module. It
|
|
3239
|
+
* reconstructs the i64 stream id from the two i32 halves, selects the
|
|
3240
|
+
* active `@stream` class's dispatch thunk from a module-level registry
|
|
3241
|
+
* (one entry per `@stream` class, in `toilstream.catalog` `stream_index`
|
|
3242
|
+
* order), switches on `event_kind` (1 connect / 2 message / 3 close /
|
|
3243
|
+
* 4 disconnect, the FIXED Part 2 ABI values), and returns the hook's
|
|
3244
|
+
* packed-i64 result (0 = no output / accept; a negative value is the
|
|
3245
|
+
* Part 3 reject/error bridge, wired with the real ring/StreamOutbound
|
|
3246
|
+
* runtime in a later increment).
|
|
3247
|
+
*
|
|
3248
|
+
* Each `@stream` class keeps its own MODULE-SINGLETON instance (a resident
|
|
3249
|
+
* per-connection box): the dispatch thunk constructs it on first use and REUSES
|
|
3250
|
+
* it across every later event, so per-connection state in instance fields
|
|
3251
|
+
* persists for the connection lifetime (the ResetMode::None resident box of
|
|
3252
|
+
* `05`). The thunk-array + the single export mirror the spec's `Streams.register`
|
|
3253
|
+
* model, but SELF-CONTAINED (no external runtime import): like
|
|
3254
|
+
* `injectDaemonHandler`, a top-level export referencing an unresolved runtime
|
|
3255
|
+
* import would be a hard compile error (TS6054), so the registry + the export
|
|
3256
|
+
* are plain module-level code emitted once (guarded by `streamExportedSources`,
|
|
3257
|
+
* exactly as `injectRestController` guards its one-per-source import).
|
|
3258
|
+
*
|
|
3259
|
+
* The `event_kind` ids are exactly the `toilstream.catalog` hook bitmask bits
|
|
3260
|
+
* plus one (connect=1 <-> bit0, message=2 <-> bit1, close=3 <-> bit2,
|
|
3261
|
+
* disconnect=4 <-> bit3, matching `streamHookMask` in `dbcatalog.ts`), so the
|
|
3262
|
+
* dispatch and the catalog never schism. `event_kind = 5` (channel, F10) is a
|
|
3263
|
+
* later increment: the base AST carries no `@channel` kind and the catalog mask
|
|
3264
|
+
* is 4-bit, so this shim emits the four lifecycle arms only.
|
|
3265
|
+
*
|
|
3266
|
+
* Active-stream selection (which registry entry a connection routes to) is
|
|
3267
|
+
* owned by the host/ring runtime (spec 5.1: the `Streams` singleton resolves the
|
|
3268
|
+
* stream identity off the ring); this increment routes to the host-selected
|
|
3269
|
+
* index, defaulting to 0, so a single-`@stream` module dispatches exactly and a
|
|
3270
|
+
* multi-`@stream` module compiles to one well-formed export.
|
|
3271
|
+
*
|
|
3272
|
+
* Only hooks the class actually declares get a dispatch arm; an event for an
|
|
3273
|
+
* absent hook falls through to `return 0` (a no-op success per the contract,
|
|
3274
|
+
* never a crash). A hook that declares parameters (the typed `@message`
|
|
3275
|
+
* `@data` arg, or a `StreamInbound`/`StreamPacket` view) is given a no-op arm
|
|
3276
|
+
* here too: the `StreamInbound`/`StreamPacket`/`StreamOutbound` runtime + the
|
|
3277
|
+
* ingress-ring read are owned by toiljs (spec 5.4) and land in a later
|
|
3278
|
+
* increment, so this self-contained shim cannot synthesize those argument
|
|
3279
|
+
* values yet; calling a zero-arg hook directly is the part that compiles and
|
|
3280
|
+
* runs today (every gating/catalog fixture uses the zero-arg/void hook form).
|
|
3281
|
+
*
|
|
3282
|
+
* Fires the 9013 warning for a `@stream` class with zero lifecycle hooks (a
|
|
3283
|
+
* hookless stream can never receive traffic), mirroring the daemon 9008 warning
|
|
3284
|
+
* shape; gating already rejects a hook outside a `@stream`.
|
|
3285
|
+
*/
|
|
3286
|
+
private injectStreamHandler;
|
|
3287
|
+
/** True if a function signature takes no parameters and returns `void` (the
|
|
3288
|
+
* required `@scheduled` handler shape, spec 03 section 3.5). A missing or
|
|
3289
|
+
* non-`void`-named return type, or any parameter, is false. */
|
|
3290
|
+
private isVoidNoArgSignature;
|
|
3106
3291
|
/**
|
|
3107
3292
|
* Bind a `@user` class to `AuthService.getUser()` typing. The lib declares
|
|
3108
3293
|
* `getUser(): AuthUser | null`; here we inject a `@global` `AuthUser` that
|
|
@@ -3343,6 +3528,8 @@ declare module "types:toilscript/src/program" {
|
|
|
3343
3528
|
instancesByName: Map<string, Element>;
|
|
3344
3529
|
/** Function decorated with `@main` (toil module entry point), if any. */
|
|
3345
3530
|
mainFunction: FunctionPrototype | null;
|
|
3531
|
+
/** Class decorated with `@daemon` (cold L4 entry), if any. At most one per project. */
|
|
3532
|
+
daemonClass: ClassPrototype | null;
|
|
3346
3533
|
/** Classes wrapping basic types like `i32`. */
|
|
3347
3534
|
wrapperClasses: Map<Type, Class>;
|
|
3348
3535
|
/** Managed classes contained in the program, by id. */
|
|
@@ -3517,6 +3704,15 @@ declare module "types:toilscript/src/program" {
|
|
|
3517
3704
|
getElementByDeclaration(declaration: DeclarationStatement): DeclaredElement | null;
|
|
3518
3705
|
/** Initializes the program and its elements prior to compilation. */
|
|
3519
3706
|
initialize(): void;
|
|
3707
|
+
/**
|
|
3708
|
+
* Enforces the project-wide rule that a compilation unit using `@stream` cannot also
|
|
3709
|
+
* declare `@service` or `@remote` anywhere (spec 03 section 4.4). The host loads one
|
|
3710
|
+
* `hot.wasm` whose surface is either a stream node or an RPC service node, never both,
|
|
3711
|
+
* so mixing them is a deploy-time ambiguity caught fail-closed at compile time. Reported
|
|
3712
|
+
* at the offending `@service`/`@remote` site. Skipped in cold mode (neither flag is
|
|
3713
|
+
* admitted there anyway).
|
|
3714
|
+
*/
|
|
3715
|
+
private enforceStreamServiceExclusion;
|
|
3520
3716
|
/** Processes overridden members by this class in a base class. */
|
|
3521
3717
|
private processOverrides;
|
|
3522
3718
|
/** Processes a single overridden member by this class in a base class. */
|
|
@@ -3675,7 +3871,15 @@ declare module "types:toilscript/src/program" {
|
|
|
3675
3871
|
/** Is a `@collection` field within a `@database` class. */
|
|
3676
3872
|
Collection = 524288,
|
|
3677
3873
|
/** Is a `@query`/`@action`/`@job`/`@derive`/`@admin` function (ToilDB kind). */
|
|
3678
|
-
DbFunction = 1048576
|
|
3874
|
+
DbFunction = 1048576,
|
|
3875
|
+
/** Is a `@stream` protocol-handler class (L2/L3, hot artifact). */
|
|
3876
|
+
Stream = 2097152,
|
|
3877
|
+
/** Is a `@daemon` L4 always-on entry class (cold artifact, at most one). */
|
|
3878
|
+
Daemon = 4194304,
|
|
3879
|
+
/** Is a `@scheduled(spec)` task method inside a `@daemon` class. */
|
|
3880
|
+
Scheduled = 8388608,
|
|
3881
|
+
/** Is a `@connect`/`@message`/`@close`/`@disconnect` stream lifecycle hook. */
|
|
3882
|
+
StreamHook = 16777216
|
|
3679
3883
|
}
|
|
3680
3884
|
export namespace DecoratorFlags {
|
|
3681
3885
|
/** Translates a decorator kind to the respective decorator flag. */
|
|
@@ -6577,7 +6781,14 @@ declare module "types:toilscript/src/ast" {
|
|
|
6577
6781
|
Job = 35,
|
|
6578
6782
|
Derive = 36,
|
|
6579
6783
|
Migrate = 37,
|
|
6580
|
-
Admin = 38
|
|
6784
|
+
Admin = 38,
|
|
6785
|
+
Daemon = 39,// @daemon class decorator (L4 entry; at most one per project)
|
|
6786
|
+
Scheduled = 40,// @scheduled(spec) method decorator inside a @daemon class
|
|
6787
|
+
Stream = 41,// @stream class decorator (L2/L3 stream protocol handler)
|
|
6788
|
+
Connect = 42,// @connect method in a @stream class (lifecycle hook)
|
|
6789
|
+
Message = 43,// @message method in a @stream class (lifecycle hook)
|
|
6790
|
+
Close = 44,// @close method in a @stream class (lifecycle hook)
|
|
6791
|
+
Disconnect = 45
|
|
6581
6792
|
}
|
|
6582
6793
|
export namespace DecoratorKind {
|
|
6583
6794
|
/** Returns the kind of the specified decorator name node. Defaults to {@link DecoratorKind.CUSTOM}. */
|
|
@@ -7910,7 +8121,21 @@ declare module "types:toilscript/src/diagnosticMessages.generated" {
|
|
|
7910
8121
|
Multiple_consecutive_numeric_separators_are_not_permitted = 6189,
|
|
7911
8122
|
This_expression_is_not_callable_because_it_is_a_get_accessor_Did_you_mean_to_use_it_without = 6234,
|
|
7912
8123
|
_super_must_be_called_before_accessing_this_in_the_constructor_of_a_derived_class = 17009,
|
|
7913
|
-
_super_must_be_called_before_accessing_a_property_of_super_in_the_constructor_of_a_derived_class = 17011
|
|
8124
|
+
_super_must_be_called_before_accessing_a_property_of_super_in_the_constructor_of_a_derived_class = 17011,
|
|
8125
|
+
Decorator_0_is_not_valid_in_the_hot_request_artifact = 9000,
|
|
8126
|
+
Decorator_0_is_not_valid_in_the_cold_daemon_artifact = 9001,
|
|
8127
|
+
Only_one_daemon_class_is_allowed_per_project = 9002,
|
|
8128
|
+
A_project_using_stream_cannot_declare_service_or_remote = 9003,
|
|
8129
|
+
Scheduled_is_only_valid_inside_a_daemon_class = 9004,
|
|
8130
|
+
Stream_hook_0_is_only_valid_inside_a_stream_class = 9005,
|
|
8131
|
+
Duplicate_stream_hook_0 = 9006,
|
|
8132
|
+
Stream_class_0_declares_no_lifecycle_hooks = 9007,
|
|
8133
|
+
Daemon_class_0_declares_no_scheduled_tasks = 9008,
|
|
8134
|
+
Decorator_0_does_not_accept_arguments = 9009,
|
|
8135
|
+
Scheduled_requires_a_single_string_schedule_argument = 9010,
|
|
8136
|
+
Scheduled_spec_0_is_not_a_valid_interval_or_cron_expression = 9011,
|
|
8137
|
+
Scheduled_handler_0_must_take_no_arguments_and_return_void = 9012,
|
|
8138
|
+
Stream_scope_must_be_a_StreamScope_enum_member = 9013
|
|
7914
8139
|
}
|
|
7915
8140
|
/** Translates a diagnostic code to its respective string. */
|
|
7916
8141
|
export function diagnosticCodeToString(code: DiagnosticCode): string;
|
|
@@ -9170,6 +9395,9 @@ declare module "types:toilscript/src/compiler" {
|
|
|
9170
9395
|
constructor();
|
|
9171
9396
|
/** WebAssembly target. Defaults to {@link Target.Wasm32}. */
|
|
9172
9397
|
target: Target;
|
|
9398
|
+
/** Toil compile surface mode. null = legacy single-artifact build (all surfaces allowed,
|
|
9399
|
+
* matching pre-split behavior). "hot" = request + stream surface. "cold" = daemon surface. */
|
|
9400
|
+
targetMode: string | null;
|
|
9173
9401
|
/** Runtime type. Defaults to Incremental GC. */
|
|
9174
9402
|
runtime: Runtime;
|
|
9175
9403
|
/** If true, indicates that debug information will be emitted by Binaryen. */
|
|
@@ -9802,6 +10030,8 @@ declare module "types:toilscript/src/index-wasm" {
|
|
|
9802
10030
|
export function setExportStart(options: Options, exportStart: string | null): void;
|
|
9803
10031
|
/** Sets the `noUnsafe` option. */
|
|
9804
10032
|
export function setNoUnsafe(options: Options, noUnsafe: boolean): void;
|
|
10033
|
+
/** Sets the `targetMode` option ("hot", "cold", or null for legacy single-artifact). */
|
|
10034
|
+
export function setTargetMode(options: Options, targetMode: string | null): void;
|
|
9805
10035
|
/** Sets the `lowMemoryLimit` option. */
|
|
9806
10036
|
export function setLowMemoryLimit(options: Options, lowMemoryLimit: number): void;
|
|
9807
10037
|
/** Sets the `exportRuntime` option. */
|
package/dist/cli.js
CHANGED
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
* Copyright 2026 Daniel Wirtz / The ToilScript Authors
|
|
5
5
|
* SPDX-License-Identifier: Apache-2.0
|
|
6
6
|
*/
|
|
7
|
-
var
|
|
8
|
-
`,o={},f=[];Object.keys(e).forEach(b=>{var p=e[b];if(p.description!=null){for(var g="";g.length<n;)g+=" ";for(g+="--"+b,p.alias&&(g+=", -"+p.alias);g.length<a;)g+=" ";var y;!t.noCategories&&p.category?(y=o[p.category])||(o[p.category]=y=[]):y=f,Array.isArray(p.description)?y.push(g+p.description[0]+p.description.slice(1).map(m=>{for(let i=0;i<a;++i)m=" "+m;return s+m}).join("")):y.push(g+p.description)}});var c=[],x=!1;return Object.keys(o).forEach(b=>{x=!0,c.push(s+" "+_n.gray(b)+s),c.push(o[b].join(s))}),x&&f.length&&c.push(s+" "+_n.gray("Other")+s),c.push(f.join(s)),c.join(s)}function be(e,t){if(e!=null)switch(t){case void 0:case"b":return!!e;case"i":return Math.trunc(e)||0;case"f":return Number(e)||0;case"s":return e===!0?"":e===!1?null:String(e);case"I":return Array.isArray(e)||(e=[e]),e.map(n=>Math.trunc(n)||0);case"F":return Array.isArray(e)||(e=[e]),e.map(n=>Number(n)||0);case"S":return Array.isArray(e)||(e=[e]),e.map(String)}}function Un(e,t,n,a){let s={};for(let[o,{type:f,mutuallyExclusive:c,isPath:x,useNodeResolution:b,cliOnly:p}]of Object.entries(e)){let g=be(t[o],f),y=be(n[o],f);if(g==null){if(y!=null){if(p)continue;if(Array.isArray(y)){let m;x&&(y=y.map(i=>tn(i,a,b))),c!=null&&(m=t[c])?s[o]=y.filter(i=>!m.includes(i)):s[o]=y.slice()}else x&&(y=tn(y,a,b)),s[o]=y}}else if(y==null)Array.isArray(g)?s[o]=g.slice():s[o]=g;else if(Array.isArray(g)){if(p){s[o]=g.slice();continue}let m;x&&(y=y.map(i=>tn(i,a,b))),c!=null&&(m=t[c])?s[o]=[...g,...y.filter(i=>!g.includes(i)&&!m.includes(i))]:s[o]=[...g,...y.filter(i=>!g.includes(i))]}else s[o]=g}return s}function vt(e){let t=A.parse(e);return t.root||(t.root="./"),A.format(t)}function tn(e,t,n=!1){return A.isAbsolute(e)?e:n&&!e.startsWith(".")&&me.resolve?me.resolve(e,{paths:[t]}):vt(A.join(t,e))}function Mn(e,t){for(let[n,{default:a}]of Object.entries(e))t[n]==null&&a!=null&&(t[n]=a)}var Fe="0.1.38",Y={version:{category:"General",description:"Prints just the compiler's version and exits.",type:"b",alias:"v"},help:{category:"General",description:"Prints this message and exits.",type:"b",alias:"h"},config:{category:"General",description:"Configuration file to apply. CLI arguments take precedence.",type:"s",cliOnly:!0},target:{category:"General",description:"Configuration file target to use. Defaults to 'release'.",type:"s",cliOnly:!0},optimize:{category:"Optimization",description:["Optimizes the module. Typical shorthands are:",""," Default optimizations -O"," Make a release build -O --noAssert"," Make a debug build --debug"," Optimize for speed -Ospeed"," Optimize for size -Osize",""],type:"b",alias:"O"},optimizeLevel:{category:"Optimization",description:"How much to focus on optimizing code. [0-3]",type:"i"},shrinkLevel:{category:"Optimization",description:"How much to focus on shrinking code size. [0-2, s=1, z=2]",type:"i"},converge:{category:"Optimization",description:"Re-optimizes until no further improvements can be made.",type:"b",default:!1},noAssert:{category:"Optimization",description:"Replaces assertions with just their value without trapping.",type:"b",default:!1},outFile:{category:"Output",description:"Specifies the WebAssembly output file (.wasm).",type:"s",alias:"o",isPath:!0},textFile:{category:"Output",description:"Specifies the WebAssembly text output file (.wat).",type:"s",alias:"t",isPath:!0},rpcModule:{category:"Output",description:"Emits a .ts module: the @data codec + the typed client-callable Server surface.",type:"s",isPath:!0},rpcRuntime:{category:"Output",description:"Import specifier for the DataWriter/DataReader codec in the emitted RPC module.",type:"s",default:"toiljs/io"},bindings:{category:"Output",description:["Specifies the bindings to generate (.js + .d.ts).",""," esm JavaScript bindings & typings for ESM integration."," raw Like esm, but exports just the instantiate function."," Useful where modules are meant to be instantiated"," multiple times or non-ESM imports must be provided."],type:"S",alias:"b"},sourceMap:{category:"Debugging",description:["Enables source map generation. Optionally takes the URL","used to reference the source map from the binary file."],type:"s"},uncheckedBehavior:{category:"Debugging",description:["Changes the behavior of unchecked() expressions.","Using this option can potentially cause breakage.",""," default The default behavior: unchecked operations are"," only used inside of unchecked()."," never Unchecked operations are never used, even when"," inside of unchecked()."," always Unchecked operations are always used if possible,"," whether or not unchecked() is used."],type:"s",default:"default"},debug:{category:"Debugging",description:"Enables debug information in emitted binaries.",type:"b",default:!1},importMemory:{category:"Features",description:"Imports the memory from 'env.memory'.",type:"b",default:!1},noExportMemory:{category:"Features",description:"Does not export the memory as 'memory'.",type:"b",default:!1},initialMemory:{category:"Features",description:"Sets the initial memory size in pages.",type:"i",default:0},maximumMemory:{category:"Features",description:"Sets the maximum memory size in pages.",type:"i",default:0},sharedMemory:{category:"Features",description:"Declare memory as shared. Requires maximumMemory.",type:"b",default:!1},zeroFilledMemory:{category:"Features",description:"Assume imported memory is zeroed. Requires importMemory.",type:"b",default:!1},importTable:{category:"Features",description:"Imports the function table from 'env.table'.",type:"b",default:!1},exportTable:{category:"Features",description:"Exports the function table as 'table'.",type:"b",default:!1},exportStart:{category:"Features",description:["Exports the start function using the specified name instead","of calling it implicitly. Useful to obtain the exported memory","before executing any code accessing it."],type:"s"},runtime:{category:"Features",description:["Specifies the runtime variant to include in the program.",""," incremental TLSF + incremental GC (default)"," minimal TLSF + lightweight GC invoked externally"," stub Minimal runtime stub (never frees)"," ... Path to a custom runtime implementation",""],type:"s",default:"incremental"},exportRuntime:{category:"Features",description:["Always exports the runtime helpers (__new, __collect, __pin etc.).","Automatically determined when generation of --bindings is enabled."],type:"b",default:!1},stackSize:{category:"Features",description:["Overrides the stack size. Only relevant for incremental GC","or when using a custom runtime that requires stack space.","Defaults to 0 without and to 32768 with incremental GC."],default:0,type:"i"},enable:{category:"Features",description:["Enables WebAssembly features being disabled by default.",""," threads Threading and atomic operations."," simd SIMD types and operations."," reference-types Reference types and operations."," gc Garbage collection (WIP)."," stringref String reference types."," relaxed-simd Relaxed SIMD operations.",""],TODO_doesNothingYet:[" exception-handling Exception handling."," tail-calls Tail call operations."," multi-value Multi value types."," memory64 Memory64 operations."," extended-const Extended const expressions."],type:"S",mutuallyExclusive:"disable"},disable:{category:"Features",description:["Disables WebAssembly features being enabled by default.",""," mutable-globals Mutable global imports and exports."," sign-extension Sign-extension operations"," nontrapping-f2i Non-trapping float to integer ops."," bulk-memory Bulk memory operations.",""],type:"S",mutuallyExclusive:"enable"},use:{category:"Features",description:["Aliases a global object under another name, e.g., to switch","the default 'Math' implementation used: --use Math=JSMath","Can also be used to introduce an integer constant."],type:"S",alias:"u"},lowMemoryLimit:{category:"Features",description:"Enforces very low (<64k) memory constraints.",default:0,type:"i"},memoryBase:{category:"Linking",description:"Sets the start offset of emitted memory segments.",type:"i",default:0},tableBase:{category:"Linking",description:"Sets the start offset of emitted table elements.",type:"i",default:0},transform:{category:"API",description:"Specifies the path to a custom transform to load.",type:"S",isPath:!0,useNodeResolution:!0},trapMode:{category:"Binaryen",description:["Sets the trap mode to use.",""," allow Allow trapping operations. This is the default."," clamp Replace trapping operations with clamping semantics."," js Replace trapping operations with JS semantics.",""],type:"s",default:"allow"},runPasses:{category:"Binaryen",description:["Specifies additional Binaryen passes to run after other","optimizations, if any. See: Binaryen/src/passes/pass.cpp"],type:"s"},noValidate:{category:"Binaryen",description:"Skips validating the module using Binaryen.",type:"b",default:!1},baseDir:{description:"Specifies the base directory of input and output files.",type:"s",default:"."},noColors:{description:"Disables terminal colors.",type:"b",default:!1},noUnsafe:{description:["Disallows the use of unsafe features in user code.","Does not affect library files and external modules."],type:"b",default:!1},disableWarning:{description:["Disables warnings matching the given diagnostic code.","If no diagnostic code is given, all warnings are disabled."],type:"I"},noEmit:{description:"Performs compilation as usual but does not emit code.",type:"b",default:!1},showConfig:{description:"Print computed compiler options and exit.",type:"b",default:!1},stats:{description:"Prints statistics on I/O and compile times.",type:"b",default:!1},pedantic:{description:"Make yourself sad for no good reason.",type:"b",default:!1},lib:{description:["Adds one or multiple paths to custom library components and","uses exports of all top-level files at this path as globals."],type:"S",isPath:!0},path:{description:["Adds one or multiple paths to package resolution, similar","to node_modules. Prefers an 'ascMain' entry in a package's","package.json and falls back to an inner 'assembly/' folder."],type:"S",isPath:!0},wasm:{description:"Uses the specified Wasm binary of the compiler.",type:"s"}," ...":{description:"Specifies node.js options (CLI only). See: node --help"},"-Os":{value:{optimizeLevel:0,shrinkLevel:1}},"-Oz":{value:{optimizeLevel:0,shrinkLevel:2}},"-O0":{value:{optimizeLevel:0,shrinkLevel:0}},"-O1":{value:{optimizeLevel:1,shrinkLevel:0}},"-O2":{value:{optimizeLevel:2,shrinkLevel:0}},"-O3":{value:{optimizeLevel:3,shrinkLevel:0}},"-O0s":{value:{optimizeLevel:0,shrinkLevel:1}},"-O1s":{value:{optimizeLevel:1,shrinkLevel:1}},"-O2s":{value:{optimizeLevel:2,shrinkLevel:1}},"-O3s":{value:{optimizeLevel:3,shrinkLevel:1}},"-O0z":{value:{optimizeLevel:0,shrinkLevel:2}},"-O1z":{value:{optimizeLevel:1,shrinkLevel:2}},"-O2z":{value:{optimizeLevel:2,shrinkLevel:2}},"-O3z":{value:{optimizeLevel:3,shrinkLevel:2}},"-Ospeed":{value:{optimizeLevel:3,shrinkLevel:0}},"-Osize":{value:{optimizeLevel:0,shrinkLevel:2,converge:!0}},"--measure":{value:{stats:!0}}},Ee="~lib/",Ae={array:`/// <reference path="./rt/index.d.ts" />
|
|
7
|
+
var le=Object.defineProperty;var Me=Object.getOwnPropertyDescriptor;var Pe=Object.getOwnPropertyNames;var Ve=Object.prototype.hasOwnProperty;var cn=(e,t,n)=>()=>{if(n)throw n[0];try{return e&&(t=e(e=0)),t}catch(a){throw n=[a],a}};var nn=(e,t)=>{for(var n in t)le(e,n,{get:t[n],enumerable:!0})},se=(e,t,n,a)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of Pe(t))!Ve.call(e,s)&&s!==n&&le(e,s,{get:()=>t[s],enumerable:!(a=Me(t,s))||a.enumerable});return e},In=(e,t,n)=>(se(e,t,"default"),n&&se(n,t,"default"));var ue={};nn(ue,{promises:()=>Ge});var Ge,fe=cn(()=>{"use strict";Ge={}});var ce={};nn(ce,{createRequire:()=>je});function je(){return function(t){throw new Error(`Cannot find module: '${t}'`)}}var de=cn(()=>{"use strict"});var Ln={};nn(Ln,{argv:()=>Xe,cwd:()=>On,exit:()=>qe,hrtime:()=>Ye,platform:()=>He,umask:()=>Ke});function On(){return"."}function Ke(){return 0}function qe(e=0){throw Error(`exit ${e}`)}function Ye(e){var t=We.call(pe),n=Math.floor(t*.001),a=Math.floor(t*1e6-n*1e9);return e&&(n-=e[0],a-=e[1],a<0&&(n--,a+=1e9)),[n,a]}var He,Xe,pe,We,kn=cn(()=>{"use strict";He="linux";Xe=[];pe=globalThis.performance||{},We=pe.now||function(){return new Date().getTime()}});var Nn={};nn(Nn,{basename:()=>et,delimiter:()=>at,dirname:()=>nt,extname:()=>tt,format:()=>it,isAbsolute:()=>Ze,join:()=>$e,normalize:()=>xe,parse:()=>rt,relative:()=>Qe,resolve:()=>dn,sep:()=>Rn,win32:()=>ot});function G(e){if(typeof e!="string")throw new TypeError("Path must be a string. Received "+JSON.stringify(e))}function he(e,t){for(var n="",a=0,s=-1,o=0,f,c=0;c<=e.length;++c){if(c<e.length)f=e.charCodeAt(c);else{if(f===47)break;f=47}if(f===47){if(!(s===c-1||o===1))if(s!==c-1&&o===2){if(n.length<2||a!==2||n.charCodeAt(n.length-1)!==46||n.charCodeAt(n.length-2)!==46){if(n.length>2){var x=n.lastIndexOf("/");if(x!==n.length-1){x===-1?(n="",a=0):(n=n.slice(0,x),a=n.length-1-n.lastIndexOf("/")),s=c,o=0;continue}}else if(n.length===2||n.length===1){n="",a=0,s=c,o=0;continue}}t&&(n.length>0?n+="/..":n="..",a=2)}else n.length>0?n+="/"+e.slice(s+1,c):n=e.slice(s+1,c),a=c-s-1;s=c,o=0}else f===46&&o!==-1?++o:o=-1}return n}function Je(e,t){var n=t.dir||t.root,a=t.base||(t.name||"")+(t.ext||"");return n?n===t.root?n+a:n+e+a:a}function dn(){for(var e="",t=!1,n,a=arguments.length-1;a>=-1&&!t;a--){var s;a>=0?s=arguments[a]:(n===void 0&&(n=On()),s=n),G(s),s.length!==0&&(e=s+"/"+e,t=s.charCodeAt(0)===47)}return e=he(e,!t),t?e.length>0?"/"+e:"/":e.length>0?e:"."}function xe(e){if(G(e),e.length===0)return".";var t=e.charCodeAt(0)===47,n=e.charCodeAt(e.length-1)===47;return e=he(e,!t),e.length===0&&!t&&(e="."),e.length>0&&n&&(e+="/"),t?"/"+e:e}function Ze(e){return G(e),e.length>0&&e.charCodeAt(0)===47}function $e(){if(arguments.length===0)return".";for(var e,t=0;t<arguments.length;++t){var n=arguments[t];G(n),n.length>0&&(e===void 0?e=n:e+="/"+n)}return e===void 0?".":xe(e)}function Qe(e,t){if(G(e),G(t),e===t||(e=dn(e),t=dn(t),e===t))return"";if(e===".")return t;for(var n=1;n<e.length&&e.charCodeAt(n)===47;++n);for(var a=e.length,s=a-n,o=1;o<t.length&&t.charCodeAt(o)===47;++o);for(var f=t.length,c=f-o,x=s<c?s:c,b=-1,p=0;p<=x;++p){if(p===x){if(c>x){if(t.charCodeAt(o+p)===47)return t.slice(o+p+1);if(p===0)return t.slice(o+p)}else s>x&&(e.charCodeAt(n+p)===47?b=p:p===0&&(b=0));break}var g=e.charCodeAt(n+p),y=t.charCodeAt(o+p);if(g!==y)break;g===47&&(b=p)}var m="";for(p=n+b+1;p<=a;++p)(p===a||e.charCodeAt(p)===47)&&(m.length===0?m+="..":m+="/..");return m.length>0?m+t.slice(o+b):(o+=b,t.charCodeAt(o)===47&&++o,t.slice(o))}function nt(e){if(G(e),e.length===0)return".";for(var t=e.charCodeAt(0),n=t===47,a=-1,s=!0,o=e.length-1;o>=1;--o)if(t=e.charCodeAt(o),t===47){if(!s){a=o;break}}else s=!1;return a===-1?n?"/":".":n&&a===1?"//":e.slice(0,a)}function et(e,t){if(t!==void 0&&typeof t!="string")throw new TypeError('"ext" argument must be a string');G(e);var n=0,a=-1,s=!0,o;if(t!==void 0&&t.length>0&&t.length<=e.length){if(t.length===e.length&&t===e)return"";var f=t.length-1,c=-1;for(o=e.length-1;o>=0;--o){var x=e.charCodeAt(o);if(x===47){if(!s){n=o+1;break}}else c===-1&&(s=!1,c=o+1),f>=0&&(x===t.charCodeAt(f)?--f===-1&&(a=o):(f=-1,a=c))}return n===a?a=c:a===-1&&(a=e.length),e.slice(n,a)}else{for(o=e.length-1;o>=0;--o)if(e.charCodeAt(o)===47){if(!s){n=o+1;break}}else a===-1&&(s=!1,a=o+1);return a===-1?"":e.slice(n,a)}}function tt(e){G(e);for(var t=-1,n=0,a=-1,s=!0,o=0,f=e.length-1;f>=0;--f){var c=e.charCodeAt(f);if(c===47){if(!s){n=f+1;break}continue}a===-1&&(s=!1,a=f+1),c===46?t===-1?t=f:o!==1&&(o=1):t!==-1&&(o=-1)}return t===-1||a===-1||o===0||o===1&&t===a-1&&t===n+1?"":e.slice(t,a)}function it(e){if(e===null||typeof e!="object")throw new TypeError('The "pathObject" argument must be of type Object. Received type '+typeof e);return Je("/",e)}function rt(e){G(e);var t={root:"",dir:"",base:"",ext:"",name:""};if(e.length===0)return t;var n=e.charCodeAt(0),a=n===47,s;a?(t.root="/",s=1):s=0;for(var o=-1,f=0,c=-1,x=!0,b=e.length-1,p=0;b>=s;--b){if(n=e.charCodeAt(b),n===47){if(!x){f=b+1;break}continue}c===-1&&(x=!1,c=b+1),n===46?o===-1?o=b:p!==1&&(p=1):o!==-1&&(p=-1)}return o===-1||c===-1||p===0||p===1&&o===c-1&&o===f+1?c!==-1&&(f===0&&a?t.base=t.name=e.slice(1,c):t.base=t.name=e.slice(f,c)):(f===0&&a?(t.name=e.slice(1,o),t.base=e.slice(1,c)):(t.name=e.slice(f,o),t.base=e.slice(f,c)),t.ext=e.slice(o,c)),f>0?t.dir=e.slice(0,f-1):a&&(t.dir="/"),t}var Rn,at,ot,Un=cn(()=>{"use strict";kn();Rn="/",at=":",ot=null});var ge={};nn(ge,{pathToFileURL:()=>lt});function st(e){return e.replace(/%/g,"%25").replace(/\\/g,"%5C").replace(/\n/g,"%0A").replace(/\r/g,"%0D").replace(/\t/g,"%09")}function lt(e){let t=dn(e);e.charCodeAt(e.length-1)===47&&t[t.length-1]!==Rn&&(t+="/");let n=new URL("file://");return n.pathname=st(t),n}var me=cn(()=>{"use strict";Un()});var Yn={};nn(Yn,{Stats:()=>zn,checkDiagnostics:()=>mn,compileString:()=>Dt,configToArguments:()=>Wn,createMemoryStream:()=>Xn,default:()=>Yn,defaultOptimizeLevel:()=>we,defaultShrinkLevel:()=>Be,definitionFiles:()=>Bt,libraryFiles:()=>H,libraryPrefix:()=>V,main:()=>De,options:()=>wt,tscOptions:()=>It,version:()=>Kn});var ut=Object.prototype.toString.call(typeof globalThis.process<"u"?globalThis.process:0)==="[object process]",M,sn,A,P,pn;ut?(M=await import("fs"),sn=await import("module"),A=await import("path"),P=globalThis.process,pn=await import("url")):(M=await Promise.resolve().then(()=>(fe(),ue)),sn=await Promise.resolve().then(()=>(de(),ce)),A=await Promise.resolve().then(()=>(Un(),Nn)),P=await Promise.resolve().then(()=>(kn(),Ln)),pn=await Promise.resolve().then(()=>(me(),ge)));var _n=typeof process<"u"&&process||{},ft=_n.env&&"CI"in _n.env,ct="\x1B[90m",dt="\x1B[91m",pt="\x1B[92m",ht="\x1B[93m",xt="\x1B[94m",gt="\x1B[95m",mt="\x1B[96m",bt="\x1B[97m",W="\x1B[0m",en=class{constructor(t){this.stream=t,this.enabled=!!(this.stream&&this.stream.isTTY||ft)}gray(t){return this.enabled?ct+t+W:t}red(t){return this.enabled?dt+t+W:t}green(t){return this.enabled?pt+t+W:t}yellow(t){return this.enabled?ht+t+W:t}blue(t){return this.enabled?xt+t+W:t}magenta(t){return this.enabled?gt+t+W:t}cyan(t){return this.enabled?mt+t+W:t}white(t){return this.enabled?bt+t+W:t}},Tn=new en(_n.stdout),kt=new en(_n.stderr);function yt(e){for(var t=0,n=0,a=e.length;n<a;++n){let s=e.charCodeAt(n);s<128?t+=1:s<2048?t+=2:(s&64512)===55296&&n+1<a&&(e.charCodeAt(n+1)&64512)===56320?(++n,t+=4):t+=3}return t}function vt(e,t,n){var a=n-t;if(a<1)return"";for(var s=null,o=[],f=0,c;t<n;)c=e[t++],c<128?o[f++]=c:c>191&&c<224?o[f++]=(c&31)<<6|e[t++]&63:c>239&&c<365?(c=((c&7)<<18|(e[t++]&63)<<12|(e[t++]&63)<<6|e[t++]&63)-65536,o[f++]=55296+(c>>10),o[f++]=56320+(c&1023)):o[f++]=(c&15)<<12|(e[t++]&63)<<6|e[t++]&63,f>=8192&&((s||(s=[])).push(String.fromCharCode(...o)),f=0);return s?(f&&s.push(String.fromCharCode(...o.slice(0,f))),s.join("")):String.fromCharCode(...o.slice(0,f))}function Ft(e,t,n){for(var a=n,s=0,o=e.length;s<o;++s){let f=e.charCodeAt(s),c;f<128?t[n++]=f:f<2048?(t[n++]=f>>6|192,t[n++]=f&63|128):(f&64512)===55296&&s+1<o&&((c=e.charCodeAt(s+1))&64512)===56320?(f=65536+((f&1023)<<10)+(c&1023),++s,t[n++]=f>>18|240,t[n++]=f>>12&63|128,t[n++]=f>>6&63|128,t[n++]=f&63|128):(t[n++]=f>>12|224,t[n++]=f>>6&63|128,t[n++]=f&63|128)}return n-a}var Cn={length:yt,read:vt,write:Ft};var be=sn.createRequire(import.meta.url);function ve(e,t,n=!0){var a={},s=[],o=[],f=[],c={};Object.keys(t).forEach(p=>{if(!p.startsWith(" ")){var g=t[p];g.alias!=null&&(typeof g.alias=="string"?c[g.alias]=p:Array.isArray(g.alias)&&g.alias.forEach(y=>c[y]=p)),n&&g.default!=null&&(a[p]=g.default)}});for(var x=0,b=(e=e.slice()).length;x<b;++x){let p=e[x];if(p=="--"){++x;break}let g=/^(?:(-\w)(?:=(.*))?|(--\w{2,})(?:=(.*))?)$/.exec(p),y,m;if(g)t[p]?y=t[m=p]:g[1]!=null?(y=t[m=c[g[1].substring(1)]],y&&g[2]!=null&&(e[x--]=g[2])):g[3]!=null&&(y=t[m=g[3].substring(2)],y&&g[4]!=null&&(e[x--]=g[4]));else if(p.charCodeAt(0)==45)y=t[m=p];else{o.push(p);continue}if(y)if(y.value)Object.keys(y.value).forEach(i=>a[i]=y.value[i]);else if(y.type==null||y.type==="b")a[m]=!0;else if(x+1<e.length&&e[x+1].charCodeAt(0)!=45)switch(y.type){case"i":a[m]=parseInt(e[++x],10);break;case"I":a[m]=(a[m]||[]).concat(parseInt(e[++x],10));break;case"f":a[m]=parseFloat(e[++x]);break;case"F":a[m]=(a[m]||[]).concat(parseFloat(e[++x]));break;case"s":a[m]=String(e[++x]);break;case"S":a[m]=(a[m]||[]).concat(e[++x].split(","));break;default:s.push(p),--x}else switch(y.type){case"i":case"f":a[m]=y.default||0;break;case"s":a[m]=y.default||"";break;case"I":case"F":case"S":a[m]=y.default||[];break;default:s.push(p)}else s.push(p)}for(;x<b;)f.push(e[x++]);return n&&Pn(t,a),{options:a,unknown:s,arguments:o,trailing:f}}function Fe(e,t){t||(t={});var n=t.indent||2,a=t.padding||24,s=t.eol||`
|
|
8
|
+
`,o={},f=[];Object.keys(e).forEach(b=>{var p=e[b];if(p.description!=null){for(var g="";g.length<n;)g+=" ";for(g+="--"+b,p.alias&&(g+=", -"+p.alias);g.length<a;)g+=" ";var y;!t.noCategories&&p.category?(y=o[p.category])||(o[p.category]=y=[]):y=f,Array.isArray(p.description)?y.push(g+p.description[0]+p.description.slice(1).map(m=>{for(let i=0;i<a;++i)m=" "+m;return s+m}).join("")):y.push(g+p.description)}});var c=[],x=!1;return Object.keys(o).forEach(b=>{x=!0,c.push(s+" "+Tn.gray(b)+s),c.push(o[b].join(s))}),x&&f.length&&c.push(s+" "+Tn.gray("Other")+s),c.push(f.join(s)),c.join(s)}function ye(e,t){if(e!=null)switch(t){case void 0:case"b":return!!e;case"i":return Math.trunc(e)||0;case"f":return Number(e)||0;case"s":return e===!0?"":e===!1?null:String(e);case"I":return Array.isArray(e)||(e=[e]),e.map(n=>Math.trunc(n)||0);case"F":return Array.isArray(e)||(e=[e]),e.map(n=>Number(n)||0);case"S":return Array.isArray(e)||(e=[e]),e.map(String)}}function Mn(e,t,n,a){let s={};for(let[o,{type:f,mutuallyExclusive:c,isPath:x,useNodeResolution:b,cliOnly:p}]of Object.entries(e)){let g=ye(t[o],f),y=ye(n[o],f);if(g==null){if(y!=null){if(p)continue;if(Array.isArray(y)){let m;x&&(y=y.map(i=>tn(i,a,b))),c!=null&&(m=t[c])?s[o]=y.filter(i=>!m.includes(i)):s[o]=y.slice()}else x&&(y=tn(y,a,b)),s[o]=y}}else if(y==null)Array.isArray(g)?s[o]=g.slice():s[o]=g;else if(Array.isArray(g)){if(p){s[o]=g.slice();continue}let m;x&&(y=y.map(i=>tn(i,a,b))),c!=null&&(m=t[c])?s[o]=[...g,...y.filter(i=>!g.includes(i)&&!m.includes(i))]:s[o]=[...g,...y.filter(i=>!g.includes(i))]}else s[o]=g}return s}function Et(e){let t=A.parse(e);return t.root||(t.root="./"),A.format(t)}function tn(e,t,n=!1){return A.isAbsolute(e)?e:n&&!e.startsWith(".")&&be.resolve?be.resolve(e,{paths:[t]}):Et(A.join(t,e))}function Pn(e,t){for(let[n,{default:a}]of Object.entries(e))t[n]==null&&a!=null&&(t[n]=a)}var Ee="0.1.41",Y={version:{category:"General",description:"Prints just the compiler's version and exits.",type:"b",alias:"v"},help:{category:"General",description:"Prints this message and exits.",type:"b",alias:"h"},config:{category:"General",description:"Configuration file to apply. CLI arguments take precedence.",type:"s",cliOnly:!0},target:{category:"General",description:"Configuration file target to use. Defaults to 'release'.",type:"s",cliOnly:!0},targetMode:{category:"General",description:"Toil compile surface mode: 'hot' (request/stream) or 'cold' (daemon). Omit for the legacy single-artifact build.",type:"s"},noConfigEntries:{category:"General",description:"Ignore the toilconfig 'entries' array and compile ONLY the entry files given on the command line. Used by the toiljs multi-artifact build, which hands each pass (request/stream/daemon) its own entry subset.",type:"b"},optimize:{category:"Optimization",description:["Optimizes the module. Typical shorthands are:",""," Default optimizations -O"," Make a release build -O --noAssert"," Make a debug build --debug"," Optimize for speed -Ospeed"," Optimize for size -Osize",""],type:"b",alias:"O"},optimizeLevel:{category:"Optimization",description:"How much to focus on optimizing code. [0-3]",type:"i"},shrinkLevel:{category:"Optimization",description:"How much to focus on shrinking code size. [0-2, s=1, z=2]",type:"i"},converge:{category:"Optimization",description:"Re-optimizes until no further improvements can be made.",type:"b",default:!1},noAssert:{category:"Optimization",description:"Replaces assertions with just their value without trapping.",type:"b",default:!1},outFile:{category:"Output",description:"Specifies the WebAssembly output file (.wasm).",type:"s",alias:"o",isPath:!0},textFile:{category:"Output",description:"Specifies the WebAssembly text output file (.wat).",type:"s",alias:"t",isPath:!0},rpcModule:{category:"Output",description:"Emits a .ts module: the @data codec + the typed client-callable Server surface.",type:"s",isPath:!0},rpcRuntime:{category:"Output",description:"Import specifier for the DataWriter/DataReader codec in the emitted RPC module.",type:"s",default:"toiljs/io"},bindings:{category:"Output",description:["Specifies the bindings to generate (.js + .d.ts).",""," esm JavaScript bindings & typings for ESM integration."," raw Like esm, but exports just the instantiate function."," Useful where modules are meant to be instantiated"," multiple times or non-ESM imports must be provided."],type:"S",alias:"b"},sourceMap:{category:"Debugging",description:["Enables source map generation. Optionally takes the URL","used to reference the source map from the binary file."],type:"s"},uncheckedBehavior:{category:"Debugging",description:["Changes the behavior of unchecked() expressions.","Using this option can potentially cause breakage.",""," default The default behavior: unchecked operations are"," only used inside of unchecked()."," never Unchecked operations are never used, even when"," inside of unchecked()."," always Unchecked operations are always used if possible,"," whether or not unchecked() is used."],type:"s",default:"default"},debug:{category:"Debugging",description:"Enables debug information in emitted binaries.",type:"b",default:!1},importMemory:{category:"Features",description:"Imports the memory from 'env.memory'.",type:"b",default:!1},noExportMemory:{category:"Features",description:"Does not export the memory as 'memory'.",type:"b",default:!1},initialMemory:{category:"Features",description:"Sets the initial memory size in pages.",type:"i",default:0},maximumMemory:{category:"Features",description:"Sets the maximum memory size in pages.",type:"i",default:0},sharedMemory:{category:"Features",description:"Declare memory as shared. Requires maximumMemory.",type:"b",default:!1},zeroFilledMemory:{category:"Features",description:"Assume imported memory is zeroed. Requires importMemory.",type:"b",default:!1},importTable:{category:"Features",description:"Imports the function table from 'env.table'.",type:"b",default:!1},exportTable:{category:"Features",description:"Exports the function table as 'table'.",type:"b",default:!1},exportStart:{category:"Features",description:["Exports the start function using the specified name instead","of calling it implicitly. Useful to obtain the exported memory","before executing any code accessing it."],type:"s"},runtime:{category:"Features",description:["Specifies the runtime variant to include in the program.",""," incremental TLSF + incremental GC (default)"," minimal TLSF + lightweight GC invoked externally"," stub Minimal runtime stub (never frees)"," ... Path to a custom runtime implementation",""],type:"s",default:"incremental"},exportRuntime:{category:"Features",description:["Always exports the runtime helpers (__new, __collect, __pin etc.).","Automatically determined when generation of --bindings is enabled."],type:"b",default:!1},stackSize:{category:"Features",description:["Overrides the stack size. Only relevant for incremental GC","or when using a custom runtime that requires stack space.","Defaults to 0 without and to 32768 with incremental GC."],default:0,type:"i"},enable:{category:"Features",description:["Enables WebAssembly features being disabled by default.",""," threads Threading and atomic operations."," simd SIMD types and operations."," reference-types Reference types and operations."," gc Garbage collection (WIP)."," stringref String reference types."," relaxed-simd Relaxed SIMD operations.",""],TODO_doesNothingYet:[" exception-handling Exception handling."," tail-calls Tail call operations."," multi-value Multi value types."," memory64 Memory64 operations."," extended-const Extended const expressions."],type:"S",mutuallyExclusive:"disable"},disable:{category:"Features",description:["Disables WebAssembly features being enabled by default.",""," mutable-globals Mutable global imports and exports."," sign-extension Sign-extension operations"," nontrapping-f2i Non-trapping float to integer ops."," bulk-memory Bulk memory operations.",""],type:"S",mutuallyExclusive:"enable"},use:{category:"Features",description:["Aliases a global object under another name, e.g., to switch","the default 'Math' implementation used: --use Math=JSMath","Can also be used to introduce an integer constant."],type:"S",alias:"u"},lowMemoryLimit:{category:"Features",description:"Enforces very low (<64k) memory constraints.",default:0,type:"i"},memoryBase:{category:"Linking",description:"Sets the start offset of emitted memory segments.",type:"i",default:0},tableBase:{category:"Linking",description:"Sets the start offset of emitted table elements.",type:"i",default:0},transform:{category:"API",description:"Specifies the path to a custom transform to load.",type:"S",isPath:!0,useNodeResolution:!0},trapMode:{category:"Binaryen",description:["Sets the trap mode to use.",""," allow Allow trapping operations. This is the default."," clamp Replace trapping operations with clamping semantics."," js Replace trapping operations with JS semantics.",""],type:"s",default:"allow"},runPasses:{category:"Binaryen",description:["Specifies additional Binaryen passes to run after other","optimizations, if any. See: Binaryen/src/passes/pass.cpp"],type:"s"},noValidate:{category:"Binaryen",description:"Skips validating the module using Binaryen.",type:"b",default:!1},baseDir:{description:"Specifies the base directory of input and output files.",type:"s",default:"."},noColors:{description:"Disables terminal colors.",type:"b",default:!1},noUnsafe:{description:["Disallows the use of unsafe features in user code.","Does not affect library files and external modules."],type:"b",default:!1},disableWarning:{description:["Disables warnings matching the given diagnostic code.","If no diagnostic code is given, all warnings are disabled."],type:"I"},noEmit:{description:"Performs compilation as usual but does not emit code.",type:"b",default:!1},showConfig:{description:"Print computed compiler options and exit.",type:"b",default:!1},stats:{description:"Prints statistics on I/O and compile times.",type:"b",default:!1},pedantic:{description:"Make yourself sad for no good reason.",type:"b",default:!1},lib:{description:["Adds one or multiple paths to custom library components and","uses exports of all top-level files at this path as globals."],type:"S",isPath:!0},path:{description:["Adds one or multiple paths to package resolution, similar","to node_modules. Prefers an 'ascMain' entry in a package's","package.json and falls back to an inner 'assembly/' folder."],type:"S",isPath:!0},wasm:{description:"Uses the specified Wasm binary of the compiler.",type:"s"}," ...":{description:"Specifies node.js options (CLI only). See: node --help"},"-Os":{value:{optimizeLevel:0,shrinkLevel:1}},"-Oz":{value:{optimizeLevel:0,shrinkLevel:2}},"-O0":{value:{optimizeLevel:0,shrinkLevel:0}},"-O1":{value:{optimizeLevel:1,shrinkLevel:0}},"-O2":{value:{optimizeLevel:2,shrinkLevel:0}},"-O3":{value:{optimizeLevel:3,shrinkLevel:0}},"-O0s":{value:{optimizeLevel:0,shrinkLevel:1}},"-O1s":{value:{optimizeLevel:1,shrinkLevel:1}},"-O2s":{value:{optimizeLevel:2,shrinkLevel:1}},"-O3s":{value:{optimizeLevel:3,shrinkLevel:1}},"-O0z":{value:{optimizeLevel:0,shrinkLevel:2}},"-O1z":{value:{optimizeLevel:1,shrinkLevel:2}},"-O2z":{value:{optimizeLevel:2,shrinkLevel:2}},"-O3z":{value:{optimizeLevel:3,shrinkLevel:2}},"-Ospeed":{value:{optimizeLevel:3,shrinkLevel:0}},"-Osize":{value:{optimizeLevel:0,shrinkLevel:2,converge:!0}},"--measure":{value:{stats:!0}}},Ae="~lib/",_e={array:`/// <reference path="./rt/index.d.ts" />
|
|
9
9
|
|
|
10
10
|
import { BLOCK_MAXSIZE } from "./rt/common";
|
|
11
11
|
import { Runtime } from "shared/runtime";
|
|
@@ -4619,8 +4619,9 @@ export namespace toildbHost {
|
|
|
4619
4619
|
export declare function get(handle: u32, keyPtr: usize, keyLen: i32): i32;
|
|
4620
4620
|
|
|
4621
4621
|
// record bounded multi-get. Input at keysPtr: u32 count + per key (u32 len +
|
|
4622
|
-
// bytes). Result (stashed): u32 count + per item u8 present
|
|
4623
|
-
//
|
|
4622
|
+
// bytes). Result (stashed): u32 count + per item u8 present, and when present
|
|
4623
|
+
// \`u32 schema_version + u32 len + bytes\`, in request order. Returns the
|
|
4624
|
+
// stashed length | negative error.
|
|
4624
4625
|
// @ts-ignore: decorator
|
|
4625
4626
|
@external("env", "data.get_many")
|
|
4626
4627
|
export declare function getMany(handle: u32, keysPtr: usize, keysLen: i32): i32;
|
|
@@ -4732,7 +4733,7 @@ export namespace toildbHost {
|
|
|
4732
4733
|
): i32;
|
|
4733
4734
|
|
|
4734
4735
|
// membership.list(limit) -> framed-list length (stashed) | negative error.
|
|
4735
|
-
// The blob is \`u32 count\` then per member \`u32 len + bytes\`.
|
|
4736
|
+
// The blob is \`u32 count\` then per member \`u32 schema_version + u32 len + bytes\`.
|
|
4736
4737
|
// @ts-ignore: decorator
|
|
4737
4738
|
@external("env", "data.membership_list")
|
|
4738
4739
|
export declare function membershipList(handle: u32, setPtr: usize, setLen: i32, limit: i32): i32;
|
|
@@ -4800,7 +4801,8 @@ export namespace toildbHost {
|
|
|
4800
4801
|
): i32;
|
|
4801
4802
|
|
|
4802
4803
|
// events.latest(limit) -> framed-list length (stashed) | negative error.
|
|
4803
|
-
// The blob is \`u32 count\` then per event \`u32 len + bytes\`,
|
|
4804
|
+
// The blob is \`u32 count\` then per event \`u32 schema_version + u32 len + bytes\`,
|
|
4805
|
+
// newest first.
|
|
4804
4806
|
// @ts-ignore: decorator
|
|
4805
4807
|
@external("env", "data.latest")
|
|
4806
4808
|
export declare function latest(handle: u32, keyPtr: usize, keyLen: i32, limit: i32): i32;
|
|
@@ -18747,7 +18749,8 @@ import { DataWriter } from "data";
|
|
|
18747
18749
|
export function __toildbResolve(name: string): u32 {
|
|
18748
18750
|
const nb = Uint8Array.wrap(String.UTF8.encode(name));
|
|
18749
18751
|
const out = new Uint8Array(4);
|
|
18750
|
-
toildbHost.resolveCollection(nb.dataStart, nb.byteLength, out.dataStart);
|
|
18752
|
+
const status = toildbHost.resolveCollection(nb.dataStart, nb.byteLength, out.dataStart);
|
|
18753
|
+
if (status < 0) abort("ToilDB collection resolve failed", "toildb", 0, 0);
|
|
18751
18754
|
return load<u32>(out.dataStart);
|
|
18752
18755
|
}
|
|
18753
18756
|
|
|
@@ -19196,7 +19199,8 @@ export class Events<K, V> {
|
|
|
19196
19199
|
}
|
|
19197
19200
|
|
|
19198
19201
|
/// The newest \`limit\` events, newest first. Decodes each framed event into a
|
|
19199
|
-
/// \`V\`. The host frames them as \`u32 count\` then per event
|
|
19202
|
+
/// \`V\`. The host frames them as \`u32 count\` then per event
|
|
19203
|
+
/// \`u32 schema_version + u32 len + bytes\`.
|
|
19200
19204
|
latest(key: K, limit: i32): V[] {
|
|
19201
19205
|
const kb = key.encode();
|
|
19202
19206
|
const status = toildbHost.latest(this.__handle, kb.dataStart, kb.byteLength, limit);
|
|
@@ -26848,7 +26852,7 @@ function loadHex(src: usize, offset: usize): u32 {
|
|
|
26848
26852
|
@final @unmanaged
|
|
26849
26853
|
export abstract class V128 {
|
|
26850
26854
|
}
|
|
26851
|
-
`},
|
|
26855
|
+
`},Te={assembly:`/**
|
|
26852
26856
|
* Environment definitions for compiling ToilScript to WebAssembly using toilscript.
|
|
26853
26857
|
* @module std/assembly
|
|
26854
26858
|
*//***/
|
|
@@ -30289,7 +30293,7 @@ declare interface Float64Array {
|
|
|
30289
30293
|
// FIXME: remove
|
|
30290
30294
|
declare function offsetof<T>(fieldName?: string): usize;
|
|
30291
30295
|
declare function idof<T>(): u32;
|
|
30292
|
-
`};var
|
|
30296
|
+
`};var hn={};nn(hn,{default:()=>xn});In(hn,Vt);import*as Vt from"binaryen";import{default as xn}from"binaryen";import*as Tt from"toilscript";var h=Tt,Vn=P.argv.indexOf("--wasm");if(~Vn){let e=String(P.argv[Vn+1]);P.argv.splice(Vn,2),h=await import(new URL(e,pn.pathToFileURL(P.cwd()+"/")))}var Gn=sn.createRequire(import.meta.url),qn=P.platform==="win32",_=qn?`\r
|
|
30293
30297
|
`:`
|
|
30294
|
-
`,Gn=Xn?"\\":"/",T=".ts",_t=`.d${T}`,xn=new RegExp("\\"+T+"$"),Tt=new RegExp("^(?!.*\\.d\\"+T+"$).*\\"+T+"$");function Te(e){return e.replace(/-/g,"_").toUpperCase()}function Ct(e){return typeof e=="string"&&e!==""}var jn=Fe,zt=Y,V=Ee,j=Ae,St=_e,Se=3,we=0;function qn(e,t=[]){return Object.keys(e||{}).forEach(n=>{let a=e[n],s=Y[n];s&&s.type==="b"?a&&t.push(`--${n}`):Array.isArray(a)?a.forEach(o=>{t.push(`--${n}`,String(o))}):t.push(`--${n}`,String(a))}),t}async function wt(e,t={}){typeof e=="string"&&(e={[`input${T}`]:e});let n=["--outFile","binary","--textFile","text"];qn(t,n);let a={},s=await Be(n.concat(Object.keys(e)),{readFile:o=>Object.prototype.hasOwnProperty.call(e,o)?e[o]:null,writeFile:(o,f)=>{a[o]=f},listFiles:()=>[]});return Object.assign(s,a)}async function Be(e,t){Array.isArray(e)||(e=qn(e)),t||(t={});let n=t.stats||new Cn,a=n.begin(),s=0,o=0,f=0,c=(jn||"").split(".");c.length===3&&(o=parseInt(c[0])|0,s=parseInt(c[1])|0,f=parseInt(c[2])|0);let x=t.stdout||Kn(),b=t.stderr||Kn(),p=t.readFile||ee,g=t.writeFile||te,y=t.listFiles||ie,m=ye(e,Y,!1),i=m.options;e=m.arguments;let zn=new en(x),H=new en(b);i.noColors&&(zn.enabled=!1,H.enabled=!1);let Yn=m.unknown;Yn.length&&Yn.forEach(r=>{b.write(`${H.yellow("WARNING ")}Unknown option '${r}'${_}`)});let Jn=m.trailing;Jn.length&&b.write(`${H.yellow("WARNING ")}Unsupported trailing arguments: ${Jn.join(" ")}${_}`);let K=null,R=null,z=(r,l={})=>(r&&b.write(`${H.red("FAILURE ")}${r.stack.replace(/^ERROR: /i,"")}${_}`),R&&R.dispose(),n.total||(n.total=n.end(a)),Object.assign({error:r,stdout:x,stderr:b,stats:n},l));if(i.version)return x.write(`Version ${jn}${_}`),z(null);let S=A.normalize(i.baseDir||"."),X=tn(i.config||"toilconfig.json",S),Sn=A.basename(X),J=A.dirname(X),N=await Ce(Sn,J,p),De=N!=null&&Array.isArray(N.entries)&&N.entries.length;if(i.help||!e.length&&!De){let r=i.help?x:b,l=i.help?zn:H;return r.write([l.white("SYNTAX")," "+l.cyan("toilscript")+" [entryFile ...] [options]","",l.white("EXAMPLES")," "+l.cyan("toilscript")+" hello"+T," "+l.cyan("toilscript")+" hello"+T+" -o hello.wasm -t hello.wat"," "+l.cyan("toilscript")+" hello1"+T+" hello2"+T+" -o -O > hello.wasm"," "+l.cyan("toilscript")+" --config toilconfig.json --target release","",l.white("OPTIONS")].concat(ve(Y,24,_)).join(_)+_),z(null)}if(!(M.promises&&M.promises.readFile)){if(p===ee)throw Error("'options.readFile' must be specified");if(g===te)throw Error("'options.writeFile' must be specified");if(y===ie)throw Error("'options.listFiles' must be specified")}let wn=new Set;wn.add(X);let Ie=i.target||"release";for(;N;){if(N.targets){let l=N.targets[Ie];l&&(i=Un(Y,i,l,J))}let r=N.options;if(r&&(i=Un(Y,i,r,J)),N.entries)for(let l of N.entries)e.push(tn(l,J));if(N.extends){if(X=tn(N.extends,J,!0),Sn=A.basename(X),J=A.dirname(X),wn.has(X))break;wn.add(X),N=await Ce(Sn,J,p)}else break}if(Mn(Y,i),i.showConfig)return b.write(JSON.stringify({options:i,entries:e},null,2)),z(null);function Zn(r){return[...new Set(r)]}let w,rn,mn,C=h.newOptions();switch(i.runtime){case"stub":rn=0;break;case"minimal":rn=1;break;case"memory":rn=3;break;default:rn=2;break}switch(i.uncheckedBehavior){default:mn=0;break;case"never":mn=1;break;case"always":mn=2;break}if(h.setTarget(C,0),h.setDebugInfo(C,!!i.debug),h.setRuntime(C,rn),h.setNoAssert(C,i.noAssert),h.setExportMemory(C,!i.noExportMemory),h.setImportMemory(C,i.importMemory),h.setInitialMemory(C,i.initialMemory>>>0),h.setMaximumMemory(C,i.maximumMemory>>>0),h.setSharedMemory(C,i.sharedMemory),h.setImportTable(C,i.importTable),h.setExportTable(C,i.exportTable),i.exportStart!=null&&h.setExportStart(C,Ct(i.exportStart)?i.exportStart:"_start"),h.setMemoryBase(C,i.memoryBase>>>0),h.setTableBase(C,i.tableBase>>>0),h.setSourceMap(C,i.sourceMap!=null),h.setUncheckedBehavior(C,mn),h.setNoUnsafe(C,i.noUnsafe),h.setPedantic(C,i.pedantic),h.setLowMemoryLimit(C,i.lowMemoryLimit>>>0),h.setExportRuntime(C,i.exportRuntime),h.setBundleVersion(C,o,s,f),!i.stackSize&&rn===2&&(i.stackSize=h.DEFAULT_STACK_SIZE),h.setStackSize(C,i.stackSize),h.setBindingsHint(C,i.bindings&&i.bindings.length>0),i.use){let r=i.use;for(let l=0,u=r.length;l<u;++l){let d=r[l],F=d.indexOf("=");if(F<0)return z(Error(`Global alias '${d}' is invalid.`));let v=d.substring(0,F).trim(),E=d.substring(F+1).trim();if(!v.length)return z(Error(`Global alias '${d}' is invalid.`));h.addGlobalAlias(C,v,E)}}let U;if((U=i.disable)!=null){typeof U=="string"&&(U=U.split(","));for(let r=0,l=U.length;r<l;++r){let u=U[r].trim(),d=h[`FEATURE_${Te(u)}`];if(!d)return z(Error(`Feature '${u}' is unknown.`));h.setFeature(C,d,!1)}}if((U=i.enable)!=null){typeof U=="string"&&(U=U.split(","));for(let r=0,l=U.length;r<l;++r){let u=U[r].trim(),d=h[`FEATURE_${Te(u)}`];if(!d)return z(Error(`Feature '${u}' is unknown.`));h.setFeature(C,d,!0)}}let Z=0,$=0;i.optimize&&(Z=Se,$=we),typeof i.optimizeLevel=="number"&&(Z=i.optimizeLevel),typeof i.shrinkLevel=="number"&&($=i.shrinkLevel),Z=Math.min(Math.max(Z,0),3),$=Math.min(Math.max($,0),2),h.setOptimizeLevelHints(C,Z,$),w=h.newProgram(C);let an=[];if(Array.isArray(t.transforms)&&an.push(...t.transforms),i.transform){let r=Zn(i.transform);for(let l=0,u=r.length;l<u;++l){let d=r[l].trim(),F,v;if(Vn.resolve)try{F=Vn.resolve(d,{paths:[P.cwd(),S]}),v=await import(dn.pathToFileURL(F)),v.default&&(v=v.default)}catch(E){try{v=Vn(F)}catch{return z(E)}}else try{v=await import(new URL(d,import.meta.url)),v.default&&(v=v.default)}catch(E){return z(E)}if(!v||typeof v!="function"&&typeof v!="object")return z(Error("not a transform: "+r[l]));an.push(v)}}try{an=an.map(r=>(typeof r=="function"&&(Object.assign(r.prototype,{program:w,binaryen:hn,baseDir:S,stdout:x,stderr:b,log:console.error,readFile:p,writeFile:g,listFiles:y}),r=new r),r))}catch(r){return z(r)}async function Bn(r,...l){for(let u=0,d=an.length;u<d;++u){let F=an[u];if(typeof F[r]=="function")try{let v=n.begin();n.transformCount++,await F[r](...l),n.transformTime+=n.end(v)}catch(v){return v}}}Object.keys(j).forEach(r=>{if(r.includes("/"))return;let l=n.begin();n.parseCount++,h.parse(w,j[r],V+r+T,!1),n.parseTime+=n.end(l)});let on=[];if(i.lib){let r=i.lib;typeof r=="string"&&(r=r.split(",")),on.push(...r.map(l=>l.trim())),on=Zn(on);for(let l=0,u=on.length;l<u;++l){let d=on[l],F;d.endsWith(T)?(F=[A.basename(d)],d=A.dirname(d)):F=await y(d,S)||[];for(let v of F){let E=await p(v,d);if(E==null)return z(Error(`Library file '${v}' not found.`));j[v.replace(xn,"")]=E;let O=n.begin();n.parseCount++,h.parse(w,E,V+v,!1),n.parseTime+=n.end(O)}}}i.path=i.path||[];let bn=new Map;async function Oe(r,l){let u=null,d=null;if(!r.startsWith(V))(u=await p(d=r+T,S))==null&&(u=await p(d=r+"/index"+T,S))==null&&(d=r+T,u=await p(r+_t,S));else{let F=r.substring(V.length),v=`${F}/index`;if(Object.prototype.hasOwnProperty.call(j,F))u=j[F],d=V+F+T;else if(Object.prototype.hasOwnProperty.call(j,v))u=j[v],d=V+v+T;else{for(let E of on)if((u=await p(F+T,E))!=null){d=V+F+T;break}else if((u=await p(v+T,E))!=null){d=V+v+T;break}if(u==null){let E=r.match(/^~lib\/((?:@[^/]+\/)?[^/]+)(?:\/(.+))?/);if(E){let O=E[1],q=E[2]||"index",Fn=bn.has(l)?bn.get(l):".",L=[],D=A.resolve(S,Fn).split(Gn);for(let B=D.length,k=Xn?1:0;B>=k;--B)D[B-1]!=="node_modules"&&L.push(`${D.slice(0,B).join(Gn)}${Gn}node_modules`);L.push(...i.path);for(let B of L.map(k=>A.relative(S,k))){let k=q;if((u=await p(A.join(B,O,k+T),S))!=null){d=`${V}${O}/${k}${T}`,bn.set(d.replace(xn,""),A.join(B,O));break}let un=`${q}/index`;if((u=await p(A.join(B,O,un+T),S))!=null){d=`${V}${O}/${un}${T}`,bn.set(d.replace(xn,""),A.join(B,O));break}}}}}}return u==null?null:{sourceText:u,sourcePath:d}}function Le(r=[]){do{let l=h.nextFile(w);if(l==null)break;r.push(l)}while(!0);return r}async function $n(){let r;for(;(r=Le()).length;){let u=[];for(let d of r){let F=h.getDependee(w,d);u.push(Oe(d,F))}u=await Promise.all(u);for(let d=0,F=r.length;d<F;++d){let v=r[d],E=u[d],O=n.begin();n.parseCount++,E?h.parse(w,E.sourceText,E.sourcePath,!1):h.parse(w,null,v+T,!1),n.parseTime+=n.end(O)}}let l=gn(w,b,i.disableWarning,t.reportDiagnostic,H.enabled);if(l){let u=Error(`${l} parse error(s)`);return u.stack=u.message,z(u)}}{let r=String(i.runtime),l=`rt/index-${r}`,u=j[l];if(u==null){if(l=r,u=await p(l+T,S),u==null)return z(Error(`Runtime '${A.resolve(S,l+T)}' is not found.`))}else l=`~lib/${l}`;let d=n.begin();n.parseCount++,h.parse(w,u,l+T,!0),n.parseTime+=n.end(d)}for(let r=0,l=e.length;r<l;++r){let u=String(e[r]),d=A.isAbsolute(u)?A.relative(S,u):A.normalize(u);d=d.replace(/\\/g,"/").replace(xn,"").replace(/\/$/,"");let F=await p(d+T,S);if(F==null){let E=`${d}/index${T}`;F=await p(E,S),F!=null?d=E:d+=T}else d+=T;let v=n.begin();n.parseCount++,h.parse(w,F,d,!0),n.parseTime+=n.end(v)}if(M.promises&&M.promises.readdir){let r=[],l=async(u,d)=>{let F;try{F=await M.promises.readdir(u,{withFileTypes:!0})}catch{return}for(let v of F){let E=v.name;if(v.isDirectory()){if(E==="node_modules"||E==="build"||E==="dist"||E.charAt(0)===".")continue;await l(A.join(u,E),d?d+"/"+E:E)}else E.endsWith(".migration"+T)&&r.push(d?d+"/"+E:E)}};await l(A.resolve(S),"");for(let u of r){let d=u.replace(/\\/g,"/"),F=await p(d,S);F!=null&&(n.parseCount++,h.parse(w,F,d,!1))}}{let r=await $n();if(r)return r}{let r=await Bn("afterParse",w.parser);if(r)return z(r)}{let r=await $n();if(r)return r}{let r=n.begin();n.initializeCount++;try{h.initializeProgram(w)}catch(l){I("initialize",l)}n.initializeTime+=n.end(r)}{let r=await Bn("afterInitialize",w);if(r)return z(r)}{let r=n.begin();n.compileCount++;try{K=h.compile(w)}catch(l){let u=gn(w,b,i.disableWarning,t.reportDiagnostic,H.enabled);if(u){let d=Error(`${u} compile error(s)`);return d.stack=d.message,z(d)}I("compile",l)}n.compileTime+=n.end(r)}R=hn.wrapModule(typeof K=="number"||K instanceof Number?h.getBinaryenModuleRef(K):K.ref);let ln=gn(w,b,i.disableWarning,t.reportDiagnostic,H.enabled);if(ln){let r=Error(`${ln} compile error(s)`);return r.stack=r.message,z(r)}{let r=await Bn("afterCompile",R);if(r)return z(r)}if(ln=gn(w,b,i.disableWarning,t.reportDiagnostic,H.enabled),ln){let r=Error(`${ln} afterCompile error(s)`);return r.stack=r.message,z(r)}if(!i.noValidate){let r=n.begin();n.validateCount++;let l=h.validate(K);if(n.validateTime+=n.end(r),!l)return z(Error("validate error"))}if(i.trapMode==="clamp"||i.trapMode==="js"){let r=n.begin();try{R.runPasses([`trap-mode-${i.trapMode}`])}catch(l){I("runPasses",l)}n.compileTime+=n.end(r)}else if(i.trapMode!=="allow")return z(Error("Unsupported trap mode"));let Qn=i.debug,ke=i.converge,ne=i.importMemory?i.zeroFilledMemory:!1,yn=[];i.runPasses&&(typeof i.runPasses=="string"&&(i.runPasses=i.runPasses.split(",")),i.runPasses.length&&i.runPasses.forEach(r=>{yn.includes(r=r.trim())||yn.push(r)}));{let r=n.begin();try{n.optimizeCount++,h.optimize(K,Z,$,Qn,ne)}catch(l){I("optimize",l)}try{R.runPasses(yn)}catch(l){I("runPasses",l)}if(ke){let l;try{let u=n.begin();n.emitCount++,l=R.emitBinary(),n.emitTime+=n.end(u)}catch(u){I("emitBinary (converge)",u)}do{try{n.optimizeCount++,h.optimize(K,Z,$,Qn,ne)}catch(d){I("optimize (converge)",d)}try{R.runPasses(yn)}catch(d){I("runPasses (converge)",d)}let u;try{let d=n.begin();n.emitCount++,u=R.emitBinary(),n.emitTime+=n.end(d)}catch(d){I("emitBinary (converge)",d)}if(u.length>=l.length){u.length>l.length&&b.write(`Last converge was suboptimal.${_}`);break}l=u}while(!0)}n.optimizeTime+=n.end(r)}let Q=[];if(!i.noEmit){if(i.binaryFile)return z(Error("Usage of the --binaryFile compiler option is no longer supported. Use --outFile instead."));let r=i.bindings||[],l=!1,u=i.outFile!=null,d=i.textFile!=null,F=u||d,v=u&&i.outFile.length>0||d&&i.textFile.length>0,E=v?(i.outFile||i.textFile).replace(/\.\w+$/,""):null,O=v?A.basename(E):"output";if(h.setBasenameHint(C,O),i.outFile!=null){let L=i.sourceMap!=null?i.sourceMap.length?i.sourceMap:`./${O}.wasm.map`:null,D=n.begin();n.emitCount++;let B;try{B=R.emitBinary(L)}catch(k){I("emitBinary",k)}if(n.emitTime+=n.end(D),i.outFile.length?Q.push(g(i.outFile,B.binary,S)):(l=!0,vn(B.binary)),B.sourceMap!="")if(i.outFile.length){let k=JSON.parse(B.sourceMap);k.sourceRoot=`./${O}`;let un=[];for(let En=0,Re=k.sources.length;En<Re;++En){let re=k.sources[En],ae=h.getSource(w,re.replace(xn,""));if(ae==null)return z(Error(`Source of file '${re}' not found.`));un[En]=ae}k.sourcesContent=un,Q.push(g(A.join(A.dirname(i.outFile),A.basename(L)).replace(/^\.\//,""),JSON.stringify(k),S))}else b.write(`Skipped source map (no output path)${_}`)}if(i.textFile!=null||!F){let L=n.begin();n.emitCount++;let D;try{hn.setOptimizeStackIR(!0),D=i.textFile?.endsWith(".wast")?R.emitText():R.emitStackIR()}catch(B){I("emitText",B)}n.emitTime+=n.end(L),i.textFile!=null&&i.textFile.length?Q.push(g(i.textFile,D,S)):l||vn(D)}let q=r.includes("esm"),Fn=!q&&r.includes("raw");if(q||Fn)if(E){let L=n.begin();n.emitCount++;let D;try{D=h.buildTSD(w,q)}catch(B){I("buildTSD",B)}n.emitTime+=n.end(L),Q.push(g(E+".d.ts",D,S))}else b.write(`Skipped TypeScript binding (no output path)${_}`);if(q||Fn)if(E){let L=n.begin();n.emitCount++;let D;try{D=h.buildJS(w,q)}catch(B){I("buildJS",B)}n.emitTime+=n.end(L),Q.push(g(E+".js",D,S))}else b.write(`Skipped JavaScript binding (no output path)${_}`);if(i.rpcModule!=null&&i.rpcModule.length){let L=n.begin();n.emitCount++;let D;try{D=h.buildServerModule(w,i.rpcRuntime||"toiljs/io")}catch(B){I("buildServerModule",B)}n.emitTime+=n.end(L),D!=null&&Q.push(g(i.rpcModule,D,S))}}try{await Promise.all(Q)}catch(r){return z(r)}return n.total=n.end(a),i.stats&&b.write(n.toString()),z(null);async function ee(r,l){let u=A.resolve(l,r);try{return n.readCount++,await M.promises.readFile(u,"utf8")}catch{return null}}async function te(r,l,u){try{n.writeCount++;let d=A.resolve(u,A.dirname(r)),F=A.join(d,A.basename(r));return await M.promises.mkdir(d,{recursive:!0}),await M.promises.writeFile(F,l),!0}catch{return!1}}async function ie(r,l){try{return n.readCount++,(await M.promises.readdir(A.join(l,r))).filter(u=>Tt.test(u))}catch{return null}}function vn(r){vn.used||(vn.used=!0,n.writeCount++),x.write(r)}function I(r,l){let u=zn.red("\u258C ");console.error([_,u,"Whoops, the ToilScript compiler has crashed during ",r," :-(",_,u,_,(typeof l.stack=="string"?[u,"Here is the stack trace hinting at the problem, perhaps it's useful?",_,u,_,l.stack.replace(/^/mg,u),_]:[u,"There is no stack trace. Perhaps a Binaryen exception above / in console?",_,u,_,u,"> "+l.stack,_]).join(""),u,_,u,"If you see where the error is, feel free to send us a pull request. If not,",_,u,"please let us know: https://github.com/dacely-cloud/toilscript/issues",_,u,_,u,"Thank you!",_].join("")),P.exit(1)}}function Hn(e){return Object.prototype.toString.call(e)==="[object Object]"}async function Ce(e,t,n){let a=await n(e,t),s=A.join(t,e);if(!a)return null;let o;try{o=JSON.parse(a)}catch(f){throw new Error(`Toilconfig is not valid json: ${s}`,{cause:f})}if(o.options&&!Hn(o.options))throw new Error(`Toilconfig.options is not an object: ${s}`);if(o.include&&!Array.isArray(o.include))throw new Error(`Toilconfig.include is not an array: ${s}`);if(o.targets){if(!Hn(o.targets))throw new Error(`Toilconfig.targets is not an object: ${s}`);let f=Object.keys(o.targets);for(let c=0;c<f.length;c++){let x=f[c];if(!Hn(o.targets[x]))throw new Error(`Toilconfig.targets.${x} is not an object: ${s}`)}}if(o.extends&&typeof o.extends!="string")throw new Error(`Toilconfig.extends is not a string: ${s}`);return o}function gn(e,t,n,a,s){typeof s>"u"&&t&&(s=t.isTTY);let o=0;do{let x=h.nextDiagnostic(e);if(!x)break;if(t){let b=p=>{if(n==null)return!1;if(!n.length)return!0;let g=h.getDiagnosticCode(p);return n.includes(g)};(h.isError(x)||!b(x))&&t.write(h.formatDiagnostic(x,s,!0)+_+_)}if(a){let b=function(g){return g&&{start:h.getRangeStart(g),end:h.getRangeEnd(g),source:p(h.getRangeSource(g))}||null},p=function(g){return g&&{normalizedPath:h.getSourceNormalizedPath(g)}||null};var f=b,c=p;a({message:h.getDiagnosticMessage(x),code:h.getDiagnosticCode(x),category:h.getDiagnosticCategory(x),range:b(h.getDiagnosticRange(x)),relatedRange:b(h.getDiagnosticRelatedRange(x))})}h.isError(x)&&++o}while(!0);return o}var Cn=class{readCount=0;writeCount=0;parseTime=0;parseCount=0;initializeTime=0;initializeCount=0;compileTime=0;compileCount=0;emitTime=0;emitCount=0;validateTime=0;validateCount=0;optimizeTime=0;optimizeCount=0;transformTime=0;transformCount=0;begin(){return P.hrtime()}end(t){let n=P.hrtime(t);return n[0]*1e9+n[1]}toString(){let t=m=>m?`${(m/1e6).toFixed(3)} ms`:"n/a",n=Object.keys(this).filter(m=>m.endsWith("Time")).map(m=>m.substring(0,m.length-4)),a=n.map(m=>t(this[`${m}Time`])),s=n.map(m=>this[`${m}Count`].toString()),o=n.reduce((m,i)=>Math.max(i.length,m),0),f=a.reduce((m,i)=>Math.max(i.length,m),0),c=s.reduce((m,i)=>Math.max(i.length,m),0),x=o+f+c+6,b=[];b.push(`\u256D\u2500${"\u2500".repeat(x)}\u2500\u256E${_}`);let p="Stats";b.push(`\u2502 ${p}${" ".repeat(x-p.length)} \u2502${_}`),b.push(`\u255E\u2550${"\u2550".repeat(o)}\u2550\u2564\u2550${"\u2550".repeat(f)}\u2550\u2564\u2550${"\u2550".repeat(c)}\u2550\u2561${_}`);for(let m=0,i=n.length;m<i;++m)b.push(`\u2502 ${n[m].padEnd(o)} \u2502 ${a[m].padStart(f)} \u2502 ${s[m].padStart(c)} \u2502${_}`);b.push(`\u251C\u2500${"\u2500".repeat(o)}\u2500\u2534\u2500${"\u2500".repeat(f)}\u2500\u2534\u2500${"\u2500".repeat(c)}\u2500\u2524${_}`);let g=`Took ${t(this.total)}`;b.push(`\u2502 ${g}${" ".repeat(x-g.length)} \u2502${_}`);let y=`${this.readCount} reads, ${this.writeCount} writes`;return b.push(`\u2502 ${y}${" ".repeat(x-y.length)} \u2502${_}`),b.push(`\u2570\u2500${"\u2500".repeat(x)}\u2500\u256F${_}`),b.join("")}},ze=typeof global<"u"&&global.Buffer?global.Buffer.allocUnsafe||(e=>new global.Buffer(e)):e=>new Uint8Array(e);function Kn(e){let t=[];return t.write=function(n){if(e&&e(n),typeof n=="string"){let a=ze(Tn.length(n));Tn.write(n,a,0),n=a}this.push(n)},t.reset=function(){t.length=0},t.toBuffer=function(){let n=0,a=0,s=this.length;for(;a<s;)n+=this[a++].length;let o=ze(n);for(n=a=0;a<s;)o.set(this[a],n),n+=this[a].length,++a;return o},t.toString=function(){let n=this.toBuffer();return Tn.read(n,0,n.length)},t}var Bt={alwaysStrict:!0,strictNullChecks:!0,noImplicitAny:!0,noImplicitReturns:!0,noImplicitThis:!0,noEmitOnError:!0,noPropertyAccessFromIndexSignature:!0,experimentalDecorators:!0,target:"esnext",noLib:!0,types:[],allowJs:!1};export{Cn as Stats,gn as checkDiagnostics,wt as compileString,qn as configToArguments,Kn as createMemoryStream,Wn as default,Se as defaultOptimizeLevel,we as defaultShrinkLevel,St as definitionFiles,j as libraryFiles,V as libraryPrefix,Be as main,zt as options,Bt as tscOptions,jn as version};
|
|
30298
|
+
`,jn=qn?"\\":"/",T=".ts",Ct=`.d${T}`,gn=new RegExp("\\"+T+"$"),zt=new RegExp("^(?!.*\\.d\\"+T+"$).*\\"+T+"$");function Ce(e){return e.replace(/-/g,"_").toUpperCase()}function St(e){return typeof e=="string"&&e!==""}var Kn=Ee,wt=Y,V=Ae,H=_e,Bt=Te,we=3,Be=0;function Wn(e,t=[]){return Object.keys(e||{}).forEach(n=>{let a=e[n],s=Y[n];s&&s.type==="b"?a&&t.push(`--${n}`):Array.isArray(a)?a.forEach(o=>{t.push(`--${n}`,String(o))}):t.push(`--${n}`,String(a))}),t}async function Dt(e,t={}){typeof e=="string"&&(e={[`input${T}`]:e});let n=["--outFile","binary","--textFile","text"];Wn(t,n);let a={},s=await De(n.concat(Object.keys(e)),{readFile:o=>Object.prototype.hasOwnProperty.call(e,o)?e[o]:null,writeFile:(o,f)=>{a[o]=f},listFiles:()=>[]});return Object.assign(s,a)}async function De(e,t){Array.isArray(e)||(e=Wn(e)),t||(t={});let n=t.stats||new zn,a=n.begin(),s=0,o=0,f=0,c=(Kn||"").split(".");c.length===3&&(o=parseInt(c[0])|0,s=parseInt(c[1])|0,f=parseInt(c[2])|0);let x=t.stdout||Xn(),b=t.stderr||Xn(),p=t.readFile||te,g=t.writeFile||ie,y=t.listFiles||re,m=ve(e,Y,!1),i=m.options;e=m.arguments;let Sn=new en(x),j=new en(b);i.noColors&&(Sn.enabled=!1,j.enabled=!1);let Jn=m.unknown;Jn.length&&Jn.forEach(r=>{b.write(`${j.yellow("WARNING ")}Unknown option '${r}'${_}`)});let Zn=m.trailing;Zn.length&&b.write(`${j.yellow("WARNING ")}Unsupported trailing arguments: ${Zn.join(" ")}${_}`);let K=null,R=null,z=(r,l={})=>(r&&b.write(`${j.red("FAILURE ")}${r.stack.replace(/^ERROR: /i,"")}${_}`),R&&R.dispose(),n.total||(n.total=n.end(a)),Object.assign({error:r,stdout:x,stderr:b,stats:n},l));if(i.version)return x.write(`Version ${Kn}${_}`),z(null);let S=A.normalize(i.baseDir||"."),X=tn(i.config||"toilconfig.json",S),wn=A.basename(X),J=A.dirname(X),N=await ze(wn,J,p),Ie=N!=null&&Array.isArray(N.entries)&&N.entries.length;if(i.help||!e.length&&!Ie){let r=i.help?x:b,l=i.help?Sn:j;return r.write([l.white("SYNTAX")," "+l.cyan("toilscript")+" [entryFile ...] [options]","",l.white("EXAMPLES")," "+l.cyan("toilscript")+" hello"+T," "+l.cyan("toilscript")+" hello"+T+" -o hello.wasm -t hello.wat"," "+l.cyan("toilscript")+" hello1"+T+" hello2"+T+" -o -O > hello.wasm"," "+l.cyan("toilscript")+" --config toilconfig.json --target release","",l.white("OPTIONS")].concat(Fe(Y,24,_)).join(_)+_),z(null)}if(!(M.promises&&M.promises.readFile)){if(p===te)throw Error("'options.readFile' must be specified");if(g===ie)throw Error("'options.writeFile' must be specified");if(y===re)throw Error("'options.listFiles' must be specified")}let Bn=new Set;Bn.add(X);let Oe=!!i.noConfigEntries,Le=i.target||"release";for(;N;){if(N.targets){let l=N.targets[Le];l&&(i=Mn(Y,i,l,J))}let r=N.options;if(r&&(i=Mn(Y,i,r,J)),N.entries&&!Oe)for(let l of N.entries)e.push(tn(l,J));if(N.extends){if(X=tn(N.extends,J,!0),wn=A.basename(X),J=A.dirname(X),Bn.has(X))break;Bn.add(X),N=await ze(wn,J,p)}else break}if(Pn(Y,i),i.showConfig)return b.write(JSON.stringify({options:i,entries:e},null,2)),z(null);function $n(r){return[...new Set(r)]}let w,rn,bn,C=h.newOptions();switch(i.runtime){case"stub":rn=0;break;case"minimal":rn=1;break;case"memory":rn=3;break;default:rn=2;break}switch(i.uncheckedBehavior){default:bn=0;break;case"never":bn=1;break;case"always":bn=2;break}let ln=null;if(i.targetMode!=null&&String(i.targetMode).length>0&&(ln=String(i.targetMode),ln!=="hot"&&ln!=="cold"))return z(Error(`Target mode '${ln}' is invalid; expected 'hot' or 'cold'.`));if(h.setTargetMode(C,ln),h.setTarget(C,0),h.setDebugInfo(C,!!i.debug),h.setRuntime(C,rn),h.setNoAssert(C,i.noAssert),h.setExportMemory(C,!i.noExportMemory),h.setImportMemory(C,i.importMemory),h.setInitialMemory(C,i.initialMemory>>>0),h.setMaximumMemory(C,i.maximumMemory>>>0),h.setSharedMemory(C,i.sharedMemory),h.setImportTable(C,i.importTable),h.setExportTable(C,i.exportTable),i.exportStart!=null&&h.setExportStart(C,St(i.exportStart)?i.exportStart:"_start"),h.setMemoryBase(C,i.memoryBase>>>0),h.setTableBase(C,i.tableBase>>>0),h.setSourceMap(C,i.sourceMap!=null),h.setUncheckedBehavior(C,bn),h.setNoUnsafe(C,i.noUnsafe),h.setPedantic(C,i.pedantic),h.setLowMemoryLimit(C,i.lowMemoryLimit>>>0),h.setExportRuntime(C,i.exportRuntime),h.setBundleVersion(C,o,s,f),!i.stackSize&&rn===2&&(i.stackSize=h.DEFAULT_STACK_SIZE),h.setStackSize(C,i.stackSize),h.setBindingsHint(C,i.bindings&&i.bindings.length>0),i.use){let r=i.use;for(let l=0,u=r.length;l<u;++l){let d=r[l],F=d.indexOf("=");if(F<0)return z(Error(`Global alias '${d}' is invalid.`));let v=d.substring(0,F).trim(),E=d.substring(F+1).trim();if(!v.length)return z(Error(`Global alias '${d}' is invalid.`));h.addGlobalAlias(C,v,E)}}let U;if((U=i.disable)!=null){typeof U=="string"&&(U=U.split(","));for(let r=0,l=U.length;r<l;++r){let u=U[r].trim(),d=h[`FEATURE_${Ce(u)}`];if(!d)return z(Error(`Feature '${u}' is unknown.`));h.setFeature(C,d,!1)}}if((U=i.enable)!=null){typeof U=="string"&&(U=U.split(","));for(let r=0,l=U.length;r<l;++r){let u=U[r].trim(),d=h[`FEATURE_${Ce(u)}`];if(!d)return z(Error(`Feature '${u}' is unknown.`));h.setFeature(C,d,!0)}}let Z=0,$=0;i.optimize&&(Z=we,$=Be),typeof i.optimizeLevel=="number"&&(Z=i.optimizeLevel),typeof i.shrinkLevel=="number"&&($=i.shrinkLevel),Z=Math.min(Math.max(Z,0),3),$=Math.min(Math.max($,0),2),h.setOptimizeLevelHints(C,Z,$),w=h.newProgram(C);let an=[];if(Array.isArray(t.transforms)&&an.push(...t.transforms),i.transform){let r=$n(i.transform);for(let l=0,u=r.length;l<u;++l){let d=r[l].trim(),F,v;if(Gn.resolve)try{F=Gn.resolve(d,{paths:[P.cwd(),S]}),v=await import(pn.pathToFileURL(F)),v.default&&(v=v.default)}catch(E){try{v=Gn(F)}catch{return z(E)}}else try{v=await import(new URL(d,import.meta.url)),v.default&&(v=v.default)}catch(E){return z(E)}if(!v||typeof v!="function"&&typeof v!="object")return z(Error("not a transform: "+r[l]));an.push(v)}}try{an=an.map(r=>(typeof r=="function"&&(Object.assign(r.prototype,{program:w,binaryen:xn,baseDir:S,stdout:x,stderr:b,log:console.error,readFile:p,writeFile:g,listFiles:y}),r=new r),r))}catch(r){return z(r)}async function Dn(r,...l){for(let u=0,d=an.length;u<d;++u){let F=an[u];if(typeof F[r]=="function")try{let v=n.begin();n.transformCount++,await F[r](...l),n.transformTime+=n.end(v)}catch(v){return v}}}Object.keys(H).forEach(r=>{if(r.includes("/"))return;let l=n.begin();n.parseCount++,h.parse(w,H[r],V+r+T,!1),n.parseTime+=n.end(l)});let on=[];if(i.lib){let r=i.lib;typeof r=="string"&&(r=r.split(",")),on.push(...r.map(l=>l.trim())),on=$n(on);for(let l=0,u=on.length;l<u;++l){let d=on[l],F;d.endsWith(T)?(F=[A.basename(d)],d=A.dirname(d)):F=await y(d,S)||[];for(let v of F){let E=await p(v,d);if(E==null)return z(Error(`Library file '${v}' not found.`));H[v.replace(gn,"")]=E;let O=n.begin();n.parseCount++,h.parse(w,E,V+v,!1),n.parseTime+=n.end(O)}}}i.path=i.path||[];let yn=new Map;async function ke(r,l){let u=null,d=null;if(!r.startsWith(V))(u=await p(d=r+T,S))==null&&(u=await p(d=r+"/index"+T,S))==null&&(d=r+T,u=await p(r+Ct,S));else{let F=r.substring(V.length),v=`${F}/index`;if(Object.prototype.hasOwnProperty.call(H,F))u=H[F],d=V+F+T;else if(Object.prototype.hasOwnProperty.call(H,v))u=H[v],d=V+v+T;else{for(let E of on)if((u=await p(F+T,E))!=null){d=V+F+T;break}else if((u=await p(v+T,E))!=null){d=V+v+T;break}if(u==null){let E=r.match(/^~lib\/((?:@[^/]+\/)?[^/]+)(?:\/(.+))?/);if(E){let O=E[1],q=E[2]||"index",En=yn.has(l)?yn.get(l):".",L=[],D=A.resolve(S,En).split(jn);for(let B=D.length,k=qn?1:0;B>=k;--B)D[B-1]!=="node_modules"&&L.push(`${D.slice(0,B).join(jn)}${jn}node_modules`);L.push(...i.path);for(let B of L.map(k=>A.relative(S,k))){let k=q;if((u=await p(A.join(B,O,k+T),S))!=null){d=`${V}${O}/${k}${T}`,yn.set(d.replace(gn,""),A.join(B,O));break}let fn=`${q}/index`;if((u=await p(A.join(B,O,fn+T),S))!=null){d=`${V}${O}/${fn}${T}`,yn.set(d.replace(gn,""),A.join(B,O));break}}}}}}return u==null?null:{sourceText:u,sourcePath:d}}function Re(r=[]){do{let l=h.nextFile(w);if(l==null)break;r.push(l)}while(!0);return r}async function Qn(){let r;for(;(r=Re()).length;){let u=[];for(let d of r){let F=h.getDependee(w,d);u.push(ke(d,F))}u=await Promise.all(u);for(let d=0,F=r.length;d<F;++d){let v=r[d],E=u[d],O=n.begin();n.parseCount++,E?h.parse(w,E.sourceText,E.sourcePath,!1):h.parse(w,null,v+T,!1),n.parseTime+=n.end(O)}}let l=mn(w,b,i.disableWarning,t.reportDiagnostic,j.enabled);if(l){let u=Error(`${l} parse error(s)`);return u.stack=u.message,z(u)}}{let r=String(i.runtime),l=`rt/index-${r}`,u=H[l];if(u==null){if(l=r,u=await p(l+T,S),u==null)return z(Error(`Runtime '${A.resolve(S,l+T)}' is not found.`))}else l=`~lib/${l}`;let d=n.begin();n.parseCount++,h.parse(w,u,l+T,!0),n.parseTime+=n.end(d)}for(let r=0,l=e.length;r<l;++r){let u=String(e[r]),d=A.isAbsolute(u)?A.relative(S,u):A.normalize(u);d=d.replace(/\\/g,"/").replace(gn,"").replace(/\/$/,"");let F=await p(d+T,S);if(F==null){let E=`${d}/index${T}`;F=await p(E,S),F!=null?d=E:d+=T}else d+=T;let v=n.begin();n.parseCount++,h.parse(w,F,d,!0),n.parseTime+=n.end(v)}if(M.promises&&M.promises.readdir){let r=[],l=async(u,d)=>{let F;try{F=await M.promises.readdir(u,{withFileTypes:!0})}catch{return}for(let v of F){let E=v.name;if(v.isDirectory()){if(E==="node_modules"||E==="build"||E==="dist"||E.charAt(0)===".")continue;await l(A.join(u,E),d?d+"/"+E:E)}else E.endsWith(".migration"+T)&&r.push(d?d+"/"+E:E)}};await l(A.resolve(S),"");for(let u of r){let d=u.replace(/\\/g,"/"),F=await p(d,S);F!=null&&(n.parseCount++,h.parse(w,F,d,!1))}}{let r=await Qn();if(r)return r}{let r=await Dn("afterParse",w.parser);if(r)return z(r)}{let r=await Qn();if(r)return r}{let r=n.begin();n.initializeCount++;try{h.initializeProgram(w)}catch(l){I("initialize",l)}n.initializeTime+=n.end(r)}{let r=await Dn("afterInitialize",w);if(r)return z(r)}{let r=n.begin();n.compileCount++;try{K=h.compile(w)}catch(l){let u=mn(w,b,i.disableWarning,t.reportDiagnostic,j.enabled);if(u){let d=Error(`${u} compile error(s)`);return d.stack=d.message,z(d)}I("compile",l)}n.compileTime+=n.end(r)}R=xn.wrapModule(typeof K=="number"||K instanceof Number?h.getBinaryenModuleRef(K):K.ref);let un=mn(w,b,i.disableWarning,t.reportDiagnostic,j.enabled);if(un){let r=Error(`${un} compile error(s)`);return r.stack=r.message,z(r)}{let r=await Dn("afterCompile",R);if(r)return z(r)}if(un=mn(w,b,i.disableWarning,t.reportDiagnostic,j.enabled),un){let r=Error(`${un} afterCompile error(s)`);return r.stack=r.message,z(r)}if(!i.noValidate){let r=n.begin();n.validateCount++;let l=h.validate(K);if(n.validateTime+=n.end(r),!l)return z(Error("validate error"))}if(i.trapMode==="clamp"||i.trapMode==="js"){let r=n.begin();try{R.runPasses([`trap-mode-${i.trapMode}`])}catch(l){I("runPasses",l)}n.compileTime+=n.end(r)}else if(i.trapMode!=="allow")return z(Error("Unsupported trap mode"));let ne=i.debug,Ne=i.converge,ee=i.importMemory?i.zeroFilledMemory:!1,vn=[];i.runPasses&&(typeof i.runPasses=="string"&&(i.runPasses=i.runPasses.split(",")),i.runPasses.length&&i.runPasses.forEach(r=>{vn.includes(r=r.trim())||vn.push(r)}));{let r=n.begin();try{n.optimizeCount++,h.optimize(K,Z,$,ne,ee)}catch(l){I("optimize",l)}try{R.runPasses(vn)}catch(l){I("runPasses",l)}if(Ne){let l;try{let u=n.begin();n.emitCount++,l=R.emitBinary(),n.emitTime+=n.end(u)}catch(u){I("emitBinary (converge)",u)}do{try{n.optimizeCount++,h.optimize(K,Z,$,ne,ee)}catch(d){I("optimize (converge)",d)}try{R.runPasses(vn)}catch(d){I("runPasses (converge)",d)}let u;try{let d=n.begin();n.emitCount++,u=R.emitBinary(),n.emitTime+=n.end(d)}catch(d){I("emitBinary (converge)",d)}if(u.length>=l.length){u.length>l.length&&b.write(`Last converge was suboptimal.${_}`);break}l=u}while(!0)}n.optimizeTime+=n.end(r)}let Q=[];if(!i.noEmit){if(i.binaryFile)return z(Error("Usage of the --binaryFile compiler option is no longer supported. Use --outFile instead."));let r=i.bindings||[],l=!1,u=i.outFile!=null,d=i.textFile!=null,F=u||d,v=u&&i.outFile.length>0||d&&i.textFile.length>0,E=v?(i.outFile||i.textFile).replace(/\.\w+$/,""):null,O=v?A.basename(E):"output";if(h.setBasenameHint(C,O),i.outFile!=null){let L=i.sourceMap!=null?i.sourceMap.length?i.sourceMap:`./${O}.wasm.map`:null,D=n.begin();n.emitCount++;let B;try{B=R.emitBinary(L)}catch(k){I("emitBinary",k)}if(n.emitTime+=n.end(D),i.outFile.length?Q.push(g(i.outFile,B.binary,S)):(l=!0,Fn(B.binary)),B.sourceMap!="")if(i.outFile.length){let k=JSON.parse(B.sourceMap);k.sourceRoot=`./${O}`;let fn=[];for(let An=0,Ue=k.sources.length;An<Ue;++An){let ae=k.sources[An],oe=h.getSource(w,ae.replace(gn,""));if(oe==null)return z(Error(`Source of file '${ae}' not found.`));fn[An]=oe}k.sourcesContent=fn,Q.push(g(A.join(A.dirname(i.outFile),A.basename(L)).replace(/^\.\//,""),JSON.stringify(k),S))}else b.write(`Skipped source map (no output path)${_}`)}if(i.textFile!=null||!F){let L=n.begin();n.emitCount++;let D;try{xn.setOptimizeStackIR(!0),D=i.textFile?.endsWith(".wast")?R.emitText():R.emitStackIR()}catch(B){I("emitText",B)}n.emitTime+=n.end(L),i.textFile!=null&&i.textFile.length?Q.push(g(i.textFile,D,S)):l||Fn(D)}let q=r.includes("esm"),En=!q&&r.includes("raw");if(q||En)if(E){let L=n.begin();n.emitCount++;let D;try{D=h.buildTSD(w,q)}catch(B){I("buildTSD",B)}n.emitTime+=n.end(L),Q.push(g(E+".d.ts",D,S))}else b.write(`Skipped TypeScript binding (no output path)${_}`);if(q||En)if(E){let L=n.begin();n.emitCount++;let D;try{D=h.buildJS(w,q)}catch(B){I("buildJS",B)}n.emitTime+=n.end(L),Q.push(g(E+".js",D,S))}else b.write(`Skipped JavaScript binding (no output path)${_}`);if(i.rpcModule!=null&&i.rpcModule.length){let L=n.begin();n.emitCount++;let D;try{D=h.buildServerModule(w,i.rpcRuntime||"toiljs/io")}catch(B){I("buildServerModule",B)}n.emitTime+=n.end(L),D!=null&&Q.push(g(i.rpcModule,D,S))}}try{await Promise.all(Q)}catch(r){return z(r)}return n.total=n.end(a),i.stats&&b.write(n.toString()),z(null);async function te(r,l){let u=A.resolve(l,r);try{return n.readCount++,await M.promises.readFile(u,"utf8")}catch{return null}}async function ie(r,l,u){try{n.writeCount++;let d=A.resolve(u,A.dirname(r)),F=A.join(d,A.basename(r));return await M.promises.mkdir(d,{recursive:!0}),await M.promises.writeFile(F,l),!0}catch{return!1}}async function re(r,l){try{return n.readCount++,(await M.promises.readdir(A.join(l,r))).filter(u=>zt.test(u))}catch{return null}}function Fn(r){Fn.used||(Fn.used=!0,n.writeCount++),x.write(r)}function I(r,l){let u=Sn.red("\u258C ");console.error([_,u,"Whoops, the ToilScript compiler has crashed during ",r," :-(",_,u,_,(typeof l.stack=="string"?[u,"Here is the stack trace hinting at the problem, perhaps it's useful?",_,u,_,l.stack.replace(/^/mg,u),_]:[u,"There is no stack trace. Perhaps a Binaryen exception above / in console?",_,u,_,u,"> "+l.stack,_]).join(""),u,_,u,"If you see where the error is, feel free to send us a pull request. If not,",_,u,"please let us know: https://github.com/dacely-cloud/toilscript/issues",_,u,_,u,"Thank you!",_].join("")),P.exit(1)}}function Hn(e){return Object.prototype.toString.call(e)==="[object Object]"}async function ze(e,t,n){let a=await n(e,t),s=A.join(t,e);if(!a)return null;let o;try{o=JSON.parse(a)}catch(f){throw new Error(`Toilconfig is not valid json: ${s}`,{cause:f})}if(o.options&&!Hn(o.options))throw new Error(`Toilconfig.options is not an object: ${s}`);if(o.include&&!Array.isArray(o.include))throw new Error(`Toilconfig.include is not an array: ${s}`);if(o.targets){if(!Hn(o.targets))throw new Error(`Toilconfig.targets is not an object: ${s}`);let f=Object.keys(o.targets);for(let c=0;c<f.length;c++){let x=f[c];if(!Hn(o.targets[x]))throw new Error(`Toilconfig.targets.${x} is not an object: ${s}`)}}if(o.extends&&typeof o.extends!="string")throw new Error(`Toilconfig.extends is not a string: ${s}`);return o}function mn(e,t,n,a,s){typeof s>"u"&&t&&(s=t.isTTY);let o=0;do{let x=h.nextDiagnostic(e);if(!x)break;if(t){let b=p=>{if(n==null)return!1;if(!n.length)return!0;let g=h.getDiagnosticCode(p);return n.includes(g)};(h.isError(x)||!b(x))&&t.write(h.formatDiagnostic(x,s,!0)+_+_)}if(a){let b=function(g){return g&&{start:h.getRangeStart(g),end:h.getRangeEnd(g),source:p(h.getRangeSource(g))}||null},p=function(g){return g&&{normalizedPath:h.getSourceNormalizedPath(g)}||null};var f=b,c=p;a({message:h.getDiagnosticMessage(x),code:h.getDiagnosticCode(x),category:h.getDiagnosticCategory(x),range:b(h.getDiagnosticRange(x)),relatedRange:b(h.getDiagnosticRelatedRange(x))})}h.isError(x)&&++o}while(!0);return o}var zn=class{readCount=0;writeCount=0;parseTime=0;parseCount=0;initializeTime=0;initializeCount=0;compileTime=0;compileCount=0;emitTime=0;emitCount=0;validateTime=0;validateCount=0;optimizeTime=0;optimizeCount=0;transformTime=0;transformCount=0;begin(){return P.hrtime()}end(t){let n=P.hrtime(t);return n[0]*1e9+n[1]}toString(){let t=m=>m?`${(m/1e6).toFixed(3)} ms`:"n/a",n=Object.keys(this).filter(m=>m.endsWith("Time")).map(m=>m.substring(0,m.length-4)),a=n.map(m=>t(this[`${m}Time`])),s=n.map(m=>this[`${m}Count`].toString()),o=n.reduce((m,i)=>Math.max(i.length,m),0),f=a.reduce((m,i)=>Math.max(i.length,m),0),c=s.reduce((m,i)=>Math.max(i.length,m),0),x=o+f+c+6,b=[];b.push(`\u256D\u2500${"\u2500".repeat(x)}\u2500\u256E${_}`);let p="Stats";b.push(`\u2502 ${p}${" ".repeat(x-p.length)} \u2502${_}`),b.push(`\u255E\u2550${"\u2550".repeat(o)}\u2550\u2564\u2550${"\u2550".repeat(f)}\u2550\u2564\u2550${"\u2550".repeat(c)}\u2550\u2561${_}`);for(let m=0,i=n.length;m<i;++m)b.push(`\u2502 ${n[m].padEnd(o)} \u2502 ${a[m].padStart(f)} \u2502 ${s[m].padStart(c)} \u2502${_}`);b.push(`\u251C\u2500${"\u2500".repeat(o)}\u2500\u2534\u2500${"\u2500".repeat(f)}\u2500\u2534\u2500${"\u2500".repeat(c)}\u2500\u2524${_}`);let g=`Took ${t(this.total)}`;b.push(`\u2502 ${g}${" ".repeat(x-g.length)} \u2502${_}`);let y=`${this.readCount} reads, ${this.writeCount} writes`;return b.push(`\u2502 ${y}${" ".repeat(x-y.length)} \u2502${_}`),b.push(`\u2570\u2500${"\u2500".repeat(x)}\u2500\u256F${_}`),b.join("")}},Se=typeof global<"u"&&global.Buffer?global.Buffer.allocUnsafe||(e=>new global.Buffer(e)):e=>new Uint8Array(e);function Xn(e){let t=[];return t.write=function(n){if(e&&e(n),typeof n=="string"){let a=Se(Cn.length(n));Cn.write(n,a,0),n=a}this.push(n)},t.reset=function(){t.length=0},t.toBuffer=function(){let n=0,a=0,s=this.length;for(;a<s;)n+=this[a++].length;let o=Se(n);for(n=a=0;a<s;)o.set(this[a],n),n+=this[a].length,++a;return o},t.toString=function(){let n=this.toBuffer();return Cn.read(n,0,n.length)},t}var It={alwaysStrict:!0,strictNullChecks:!0,noImplicitAny:!0,noImplicitReturns:!0,noImplicitThis:!0,noEmitOnError:!0,noPropertyAccessFromIndexSignature:!0,experimentalDecorators:!0,target:"esnext",noLib:!0,types:[],allowJs:!1};export{zn as Stats,mn as checkDiagnostics,Dt as compileString,Wn as configToArguments,Xn as createMemoryStream,Yn as default,we as defaultOptimizeLevel,Be as defaultShrinkLevel,Bt as definitionFiles,H as libraryFiles,V as libraryPrefix,De as main,wt as options,It as tscOptions,Kn as version};
|
|
30295
30299
|
//# sourceMappingURL=cli.js.map
|