Skip to content
This repository was archived by the owner on Jul 30, 2024. It is now read-only.

Drop Factory macro #461

Merged
merged 1 commit into from
Jul 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,3 @@ for {
console.log("output3 =", output3)
}
```

## Note

This facade leverages [`@Factory` marcro](https://github.com/exoego/scalajs-types-util#factory-macro) to create highly-optimized factory method without boilerplate.
13 changes: 10 additions & 3 deletions app/nodejs-v16/src/main/scala/io/scalajs/nodejs/Require.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package io.scalajs.nodejs

import _root_.net.exoego.scalajs.types.util.Factory

import scala.scalajs.js
import scala.scalajs.js.annotation.JSGlobal

Expand All @@ -26,7 +24,16 @@ trait RequireResolver extends js.Object {
def paths(requiest: String): js.Array[String] = js.native
}

@Factory
trait ResolveOptions extends js.Object {
var paths: js.UndefOr[js.Array[String]] = js.undefined
}
object ResolveOptions {
def apply(
paths: js.UndefOr[js.Array[String]] = js.undefined
): ResolveOptions = {
val _obj$ = js.Dynamic.literal(
)
paths.foreach(_v => _obj$.updateDynamic("paths")(_v.asInstanceOf[js.Any]))
_obj$.asInstanceOf[ResolveOptions]
}
}
14 changes: 12 additions & 2 deletions app/nodejs-v16/src/main/scala/io/scalajs/nodejs/buffer/Blob.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package io.scalajs.nodejs.buffer

import com.thoughtworks.enableMembersIf
import io.scalajs.nodejs.webstream
import net.exoego.scalajs.types.util.Factory

import scala.scalajs.js
import scala.scalajs.js.annotation.{JSImport, JSName}
Expand Down Expand Up @@ -36,8 +35,19 @@ class Blob() extends js.Object {
def stream(): webstream.ReadableStream = js.native
}

@Factory
trait BlobOptions extends js.Object {
var encoding: js.UndefOr[String] = js.undefined
var `type`: js.UndefOr[String] = js.undefined
}
object BlobOptions {
def apply(
encoding: js.UndefOr[String] = js.undefined,
`type`: js.UndefOr[String] = js.undefined
): BlobOptions = {
val _obj$ = js.Dynamic.literal(
)
encoding.foreach(_v => _obj$.updateDynamic("encoding")(_v.asInstanceOf[js.Any]))
`type`.foreach(_v => _obj$.updateDynamic("type")(_v.asInstanceOf[js.Any]))
_obj$.asInstanceOf[BlobOptions]
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.scalajs.nodejs.child_process

import io.scalajs.nodejs.{GID, UID}
import net.exoego.scalajs.types.util.Factory

import scala.scalajs.js
import scala.scalajs.js.|
Expand All @@ -11,7 +10,6 @@ import scala.scalajs.js.|
* Note: Never pass unsanitized user input to this function. Any input containing shell meta-characters may be used to
* trigger arbitrary command execution.
*/
@Factory
trait ExecFileSyncOptions extends js.Object {

/** Current working directory of the child process
Expand Down Expand Up @@ -65,3 +63,36 @@ trait ExecFileSyncOptions extends js.Object {
*/
var windowsHide: js.UndefOr[Boolean] = js.undefined
}

object ExecFileSyncOptions {
def apply(
cwd: js.UndefOr[String] = js.undefined,
input: js.UndefOr[Input] = js.undefined,
stdio: js.UndefOr[StdIo] = js.undefined,
env: js.UndefOr[js.Object] = js.undefined,
encoding: js.UndefOr[String] = js.undefined,
shell: js.UndefOr[Boolean | String] = js.undefined,
timeout: js.UndefOr[Int] = js.undefined,
maxBuffer: js.UndefOr[Int] = js.undefined,
killSignal: js.UndefOr[KillSignal] = js.undefined,
uid: js.UndefOr[UID] = js.undefined,
gid: js.UndefOr[GID] = js.undefined,
windowsHide: js.UndefOr[Boolean] = js.undefined
): ExecFileSyncOptions = {
val _obj$ = js.Dynamic.literal(
)
cwd.foreach(_v => _obj$.updateDynamic("cwd")(_v.asInstanceOf[js.Any]))
input.foreach(_v => _obj$.updateDynamic("input")(_v.asInstanceOf[js.Any]))
stdio.foreach(_v => _obj$.updateDynamic("stdio")(_v.asInstanceOf[js.Any]))
env.foreach(_v => _obj$.updateDynamic("env")(_v.asInstanceOf[js.Any]))
encoding.foreach(_v => _obj$.updateDynamic("encoding")(_v.asInstanceOf[js.Any]))
shell.foreach(_v => _obj$.updateDynamic("shell")(_v.asInstanceOf[js.Any]))
timeout.foreach(_v => _obj$.updateDynamic("timeout")(_v.asInstanceOf[js.Any]))
maxBuffer.foreach(_v => _obj$.updateDynamic("maxBuffer")(_v.asInstanceOf[js.Any]))
killSignal.foreach(_v => _obj$.updateDynamic("killSignal")(_v.asInstanceOf[js.Any]))
uid.foreach(_v => _obj$.updateDynamic("uid")(_v.asInstanceOf[js.Any]))
gid.foreach(_v => _obj$.updateDynamic("gid")(_v.asInstanceOf[js.Any]))
windowsHide.foreach(_v => _obj$.updateDynamic("windowsHide")(_v.asInstanceOf[js.Any]))
_obj$.asInstanceOf[ExecFileSyncOptions]
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package io.scalajs.nodejs
package child_process

import _root_.net.exoego.scalajs.types.util.Factory

import scala.scalajs.js
import scala.scalajs.js.|

Expand All @@ -11,7 +9,6 @@ import scala.scalajs.js.|
* Note: Never pass unsanitized user input to this function. Any input containing shell meta-characters may be used to
* trigger arbitrary command execution.
*/
@Factory
trait ExecOptions extends js.Object {

/** Current working directory of the child process
Expand Down Expand Up @@ -61,3 +58,33 @@ trait ExecOptions extends js.Object {
*/
var windowsVerbatimArguments: js.UndefOr[Boolean] = js.undefined
}
object ExecOptions {
def apply(
cwd: js.UndefOr[String] = js.undefined,
env: js.UndefOr[js.Object] = js.undefined,
encoding: js.UndefOr[String] = js.undefined,
shell: js.UndefOr[Boolean | String] = js.undefined,
timeout: js.UndefOr[Int] = js.undefined,
maxBuffer: js.UndefOr[Int] = js.undefined,
killSignal: js.UndefOr[KillSignal] = js.undefined,
uid: js.UndefOr[UID] = js.undefined,
gid: js.UndefOr[GID] = js.undefined,
windowsHide: js.UndefOr[Boolean] = js.undefined,
windowsVerbatimArguments: js.UndefOr[Boolean] = js.undefined
): ExecOptions = {
val _obj$ = js.Dynamic.literal(
)
cwd.foreach(_v => _obj$.updateDynamic("cwd")(_v.asInstanceOf[js.Any]))
env.foreach(_v => _obj$.updateDynamic("env")(_v.asInstanceOf[js.Any]))
encoding.foreach(_v => _obj$.updateDynamic("encoding")(_v.asInstanceOf[js.Any]))
shell.foreach(_v => _obj$.updateDynamic("shell")(_v.asInstanceOf[js.Any]))
timeout.foreach(_v => _obj$.updateDynamic("timeout")(_v.asInstanceOf[js.Any]))
maxBuffer.foreach(_v => _obj$.updateDynamic("maxBuffer")(_v.asInstanceOf[js.Any]))
killSignal.foreach(_v => _obj$.updateDynamic("killSignal")(_v.asInstanceOf[js.Any]))
uid.foreach(_v => _obj$.updateDynamic("uid")(_v.asInstanceOf[js.Any]))
gid.foreach(_v => _obj$.updateDynamic("gid")(_v.asInstanceOf[js.Any]))
windowsHide.foreach(_v => _obj$.updateDynamic("windowsHide")(_v.asInstanceOf[js.Any]))
windowsVerbatimArguments.foreach(_v => _obj$.updateDynamic("windowsVerbatimArguments")(_v.asInstanceOf[js.Any]))
_obj$.asInstanceOf[ExecOptions]
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
package io.scalajs.nodejs.child_process

import net.exoego.scalajs.types.util.Factory

import scala.scalajs.js

@Factory
trait SendOptions extends js.Object {
var keepOpen: js.UndefOr[Boolean] = js.undefined
}
object SendOptions {
def apply(
keepOpen: js.UndefOr[Boolean] = js.undefined
): SendOptions = {
val _obj$ = js.Dynamic.literal(
)
keepOpen.foreach(_v => _obj$.updateDynamic("keepOpen")(_v.asInstanceOf[js.Any]))
_obj$.asInstanceOf[SendOptions]
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package io.scalajs.nodejs.child_process

import net.exoego.scalajs.types.util.Factory

import scala.scalajs.js
import scala.scalajs.js.|

@Factory
trait SpawnSyncResult extends js.Object {
var pid: Int
var output: js.Array[Output]
Expand All @@ -15,3 +12,26 @@ trait SpawnSyncResult extends js.Object {
var signal: String | Null
var error: js.UndefOr[js.Error] = js.undefined
}

object SpawnSyncResult {
def apply(
pid: Int,
output: js.Array[Output],
stdout: Output,
stderr: Output,
status: Int | Null = null,
signal: String | Null = null,
error: js.UndefOr[js.Error] = js.undefined
): SpawnSyncResult = {
val _obj$ = js.Dynamic.literal(
"pid" -> pid.asInstanceOf[js.Any],
"output" -> output.asInstanceOf[js.Any],
"stdout" -> stdout.asInstanceOf[js.Any],
"stderr" -> stderr.asInstanceOf[js.Any],
"status" -> status.asInstanceOf[js.Any],
"signal" -> signal.asInstanceOf[js.Any]
)
error.foreach(_v => _obj$.updateDynamic("error")(_v.asInstanceOf[js.Any]))
_obj$.asInstanceOf[SpawnSyncResult]
}
}
Original file line number Diff line number Diff line change
@@ -1,48 +1,75 @@
package io.scalajs.nodejs.cluster

import net.exoego.scalajs.types.util.Factory

import io.scalajs.nodejs.{GID, UID}

import scala.scalajs.js
import scala.scalajs.js.|

/** Cluster Settings
*/
@Factory
@js.native
trait ClusterSettings extends js.Object {

/** <Array> list of string arguments passed to the Node.js executable. (Default=process.execArgv) */
var execArgv: js.Array[String] = js.native
var execArgv: js.Array[String]

/** <String> file path to worker file. (Default=process.argv[1]) */
var exec: String = js.native
var exec: String

/** <Array> string arguments passed to worker. (Default=process.argv.slice(2)) */
var args: js.Array[String] = js.native
var args: js.Array[String]

/** <Boolean> whether or not to send output to parent's stdio. (Default=false) */
var silent: Boolean = js.native
var silent: Boolean

/** Specify the kind of serialization used for sending messages between processes. Possible values are 'json' and
* 'advanced'. See Advanced Serialization for more details. Default: 'json'.
*
* From Node.js v13.2.0, v12.16.0.
*/
var serialization: js.UndefOr[String] = js.native
var serialization: js.UndefOr[String]

/** <Number> Sets the user identity of the process. (See setuid(2).) */
var uid: UID = js.native
var uid: UID

/** <Number> Sets the group identity of the process. (See setgid(2).) */
var gid: GID = js.native
var gid: GID

var stdio: js.Array[js.Any]

var stdio: js.Array[js.Any] = js.native
var inspectPort: Int | js.Function

var inspectPort: Int | js.Function = js.native
var cwd: String

var cwd: String = js.native
var windowsHide: Boolean
}

var windowsHide: Boolean = js.native
object ClusterSettings {
def apply(
execArgv: js.Array[String],
exec: String,
args: js.Array[String],
silent: Boolean,
uid: UID,
gid: GID,
stdio: js.Array[js.Any],
inspectPort: Int | js.Function,
cwd: String,
windowsHide: Boolean,
serialization: js.UndefOr[String] = js.undefined
): ClusterSettings = {
val _obj$ = js.Dynamic.literal(
"execArgv" -> execArgv.asInstanceOf[js.Any],
"exec" -> exec.asInstanceOf[js.Any],
"args" -> args.asInstanceOf[js.Any],
"silent" -> silent.asInstanceOf[js.Any],
"serialization" -> serialization.asInstanceOf[js.Any],
"uid" -> uid.asInstanceOf[js.Any],
"gid" -> gid.asInstanceOf[js.Any],
"stdio" -> stdio.asInstanceOf[js.Any],
"inspectPort" -> inspectPort.asInstanceOf[js.Any],
"cwd" -> cwd.asInstanceOf[js.Any],
"windowsHide" -> windowsHide.asInstanceOf[js.Any]
)
_obj$.asInstanceOf[ClusterSettings]
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package io.scalajs.nodejs.console_module

import net.exoego.scalajs.types.util.Factory

import scala.scalajs.js

@Factory
trait ConsoleDirOptions extends js.Object {

/** if true then the object's non-enumerable and symbol properties will be shown too. Defaults to `false`.
Expand All @@ -21,3 +18,18 @@ trait ConsoleDirOptions extends js.Object {
*/
var colors: js.UndefOr[Boolean] = js.undefined
}

object ConsoleDirOptions {
def apply(
showHidden: js.UndefOr[Boolean] = js.undefined,
depth: js.UndefOr[Int] = js.undefined,
colors: js.UndefOr[Boolean] = js.undefined
): ConsoleDirOptions = {
val _obj$ = js.Dynamic.literal(
)
showHidden.foreach(_v => _obj$.updateDynamic("showHidden")(_v.asInstanceOf[js.Any]))
depth.foreach(_v => _obj$.updateDynamic("depth")(_v.asInstanceOf[js.Any]))
colors.foreach(_v => _obj$.updateDynamic("colors")(_v.asInstanceOf[js.Any]))
_obj$.asInstanceOf[ConsoleDirOptions]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ package io.scalajs.nodejs.console_module

import io.scalajs.nodejs.stream.IWritable
import io.scalajs.nodejs.util.InspectOptions
import net.exoego.scalajs.types.util.Factory

import scala.scalajs.js
import scala.scalajs.js.|

@Factory
trait ConsoleOptions extends js.Object {
var stdout: IWritable
var stderr: js.UndefOr[IWritable] = js.undefined
Expand All @@ -31,3 +29,24 @@ trait ConsoleOptions extends js.Object {
*/
var groupIndentation: js.UndefOr[Int] = js.undefined
}

object ConsoleOptions {
def apply(
stdout: IWritable,
stderr: js.UndefOr[IWritable] = js.undefined,
ignoreErrors: js.UndefOr[Boolean] = js.undefined,
colorMode: js.UndefOr[Boolean | String] = js.undefined,
inspectOptions: js.UndefOr[InspectOptions] = js.undefined,
groupIndentation: js.UndefOr[Int] = js.undefined
): ConsoleOptions = {
val _obj$ = js.Dynamic.literal(
"stdout" -> stdout.asInstanceOf[js.Any]
)
stderr.foreach(_v => _obj$.updateDynamic("stderr")(_v.asInstanceOf[js.Any]))
ignoreErrors.foreach(_v => _obj$.updateDynamic("ignoreErrors")(_v.asInstanceOf[js.Any]))
colorMode.foreach(_v => _obj$.updateDynamic("colorMode")(_v.asInstanceOf[js.Any]))
inspectOptions.foreach(_v => _obj$.updateDynamic("inspectOptions")(_v.asInstanceOf[js.Any]))
groupIndentation.foreach(_v => _obj$.updateDynamic("groupIndentation")(_v.asInstanceOf[js.Any]))
_obj$.asInstanceOf[ConsoleOptions]
}
}
Loading