@mojir/dvala 0.0.32 → 0.0.33
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/cli.js +70 -27
- package/package.json +1 -1
package/dist/cli/cli.js
CHANGED
|
@@ -480,7 +480,7 @@ function findAllOccurrences(input, pattern) {
|
|
|
480
480
|
}
|
|
481
481
|
//#endregion
|
|
482
482
|
//#region package.json
|
|
483
|
-
var version = "0.0.
|
|
483
|
+
var version = "0.0.33";
|
|
484
484
|
//#endregion
|
|
485
485
|
//#region src/typeGuards/string.ts
|
|
486
486
|
function isString(value, options = {}) {
|
|
@@ -8351,32 +8351,32 @@ const timeModule = {
|
|
|
8351
8351
|
docs: moduleDocsFromFunctions(timeFunctions)
|
|
8352
8352
|
};
|
|
8353
8353
|
const handlerModule = {
|
|
8354
|
-
name: "
|
|
8354
|
+
name: "effectHandler",
|
|
8355
8355
|
functions: {},
|
|
8356
8356
|
source: "{\n retry: (n) -> (arg, eff, nxt) ->\n if eff == @dvala.error then nxt(eff, arg)\n else\n loop (remaining = n) ->\n handle nxt(eff, arg)\n with @dvala.error(msg) ->\n if remaining > 0 then recur(remaining - 1)\n else nxt(@dvala.error, msg)\n end\n end\n end,\n\n fallback: (value) -> @dvala.error(msg) -> value\n}\n",
|
|
8357
8357
|
docs: {
|
|
8358
8358
|
"retry": {
|
|
8359
|
-
category: "
|
|
8359
|
+
category: "effectHandler",
|
|
8360
8360
|
returns: { type: "function" },
|
|
8361
8361
|
args: { n: { type: "integer" } },
|
|
8362
8362
|
variants: [{ argumentNames: ["n"] }],
|
|
8363
8363
|
description: "Returns a handler function that retries failing effects up to `$n` times. On final failure, propagates the original error. Passes `@dvala.error` through unchanged.",
|
|
8364
8364
|
examples: [
|
|
8365
|
-
"let { retry } = import(
|
|
8366
|
-
"let { retry, fallback } = import(
|
|
8367
|
-
"let { retry } = import(
|
|
8365
|
+
"let { retry } = import(effectHandler); retry(3)",
|
|
8366
|
+
"let { retry, fallback } = import(effectHandler);\nperform(@my.eff, \"data\") ||> [retry(2), @my.eff(x) -> x ++ \"!\", fallback(\"gave up\")]",
|
|
8367
|
+
"let { retry } = import(effectHandler);\nhandle perform(@my.eff, 10) with [retry(3), @my.eff(x) -> x * 2] end"
|
|
8368
8368
|
]
|
|
8369
8369
|
},
|
|
8370
8370
|
"fallback": {
|
|
8371
|
-
category: "
|
|
8371
|
+
category: "effectHandler",
|
|
8372
8372
|
returns: { type: "function" },
|
|
8373
8373
|
args: { value: { type: "any" } },
|
|
8374
8374
|
variants: [{ argumentNames: ["value"] }],
|
|
8375
8375
|
description: "Returns a handler function that catches `@dvala.error` and returns `$value` instead.",
|
|
8376
8376
|
examples: [
|
|
8377
|
-
"let { fallback } = import(
|
|
8378
|
-
"let { fallback } = import(
|
|
8379
|
-
"let { fallback } = import(
|
|
8377
|
+
"let { fallback } = import(effectHandler); fallback(0)",
|
|
8378
|
+
"let { fallback } = import(effectHandler);\n(0 / 0) ||> fallback(0)",
|
|
8379
|
+
"let { fallback } = import(effectHandler);\nhandle let x = 0 / 0; x + 1 with fallback(0) end"
|
|
8380
8380
|
]
|
|
8381
8381
|
}
|
|
8382
8382
|
}
|
|
@@ -24400,13 +24400,20 @@ const standardEffects = {
|
|
|
24400
24400
|
description: "Value to print."
|
|
24401
24401
|
} },
|
|
24402
24402
|
variants: [{ argumentNames: ["value"] }],
|
|
24403
|
-
examples: [
|
|
24404
|
-
|
|
24405
|
-
|
|
24406
|
-
|
|
24407
|
-
|
|
24408
|
-
|
|
24409
|
-
|
|
24403
|
+
examples: [
|
|
24404
|
+
{
|
|
24405
|
+
code: "perform(@dvala.io.print, \"hello\")",
|
|
24406
|
+
noRun: true
|
|
24407
|
+
},
|
|
24408
|
+
{
|
|
24409
|
+
code: "perform(@dvala.io.print, 42)",
|
|
24410
|
+
noRun: true
|
|
24411
|
+
},
|
|
24412
|
+
{
|
|
24413
|
+
code: "perform(@dvala.io.print, {name: \"Alice\", age: 30})",
|
|
24414
|
+
noRun: true
|
|
24415
|
+
}
|
|
24416
|
+
],
|
|
24410
24417
|
seeAlso: [
|
|
24411
24418
|
"-effect-dvala.io.error",
|
|
24412
24419
|
"-effect-dvala.io.read",
|
|
@@ -24439,6 +24446,9 @@ const standardEffects = {
|
|
|
24439
24446
|
examples: [{
|
|
24440
24447
|
code: "perform(@dvala.io.error, \"something went wrong\")",
|
|
24441
24448
|
noRun: true
|
|
24449
|
+
}, {
|
|
24450
|
+
code: "perform(@dvala.io.error, {code: 500, message: \"Internal error\"})",
|
|
24451
|
+
noRun: true
|
|
24442
24452
|
}],
|
|
24443
24453
|
seeAlso: [
|
|
24444
24454
|
"-effect-dvala.io.print",
|
|
@@ -24470,7 +24480,13 @@ const standardEffects = {
|
|
|
24470
24480
|
description: "Optional prompt message to display."
|
|
24471
24481
|
} },
|
|
24472
24482
|
variants: [{ argumentNames: [] }, { argumentNames: ["message"] }],
|
|
24473
|
-
examples: [
|
|
24483
|
+
examples: [{
|
|
24484
|
+
code: "let name = perform(@dvala.io.read, \"What is your name?\"); \"Hello, \" ++ name",
|
|
24485
|
+
noRun: true
|
|
24486
|
+
}, {
|
|
24487
|
+
code: "let input = perform(@dvala.io.read); input ?? \"no input\"",
|
|
24488
|
+
noRun: true
|
|
24489
|
+
}],
|
|
24474
24490
|
seeAlso: [
|
|
24475
24491
|
"-effect-dvala.io.readStdin",
|
|
24476
24492
|
"-effect-dvala.io.print",
|
|
@@ -24483,9 +24499,8 @@ const standardEffects = {
|
|
|
24483
24499
|
},
|
|
24484
24500
|
"dvala.io.pick": {
|
|
24485
24501
|
handler: (arg, k, sourceCodeInfo) => {
|
|
24486
|
-
const
|
|
24487
|
-
const
|
|
24488
|
-
const options = argObj?.["options"];
|
|
24502
|
+
const items = Array.isArray(arg) ? arg : arg?.["items"];
|
|
24503
|
+
const options = Array.isArray(arg) ? void 0 : arg?.["options"];
|
|
24489
24504
|
if (!Array.isArray(items)) throw new DvalaError(`dvala.io.pick: first argument must be an array, got ${typeof items}`, sourceCodeInfo);
|
|
24490
24505
|
if (items.length === 0) throw new DvalaError("dvala.io.pick: items array must not be empty", sourceCodeInfo);
|
|
24491
24506
|
for (let i = 0; i < items.length; i++) if (typeof items[i] !== "string") throw new DvalaError(`dvala.io.pick: items[${i}] must be a string, got ${typeof items[i]}`, sourceCodeInfo);
|
|
@@ -24535,12 +24550,12 @@ const standardEffects = {
|
|
|
24535
24550
|
},
|
|
24536
24551
|
docs: {
|
|
24537
24552
|
category: "effect",
|
|
24538
|
-
description: "Presents a
|
|
24553
|
+
description: "Presents a list of items and asks the user to choose one. Accepts either a plain array of strings or an object with `items` and optional `options`. Resumes with the index of the chosen item, or `null` if the user cancels.",
|
|
24539
24554
|
returns: { type: ["integer", "null"] },
|
|
24540
24555
|
args: {
|
|
24541
24556
|
items: {
|
|
24542
24557
|
type: "array",
|
|
24543
|
-
description: "Non-empty array of strings to display."
|
|
24558
|
+
description: "Non-empty array of strings to display. Can be passed directly as the arg."
|
|
24544
24559
|
},
|
|
24545
24560
|
options: {
|
|
24546
24561
|
type: "object",
|
|
@@ -24548,7 +24563,20 @@ const standardEffects = {
|
|
|
24548
24563
|
}
|
|
24549
24564
|
},
|
|
24550
24565
|
variants: [{ argumentNames: ["items"] }, { argumentNames: ["items", "options"] }],
|
|
24551
|
-
examples: [
|
|
24566
|
+
examples: [
|
|
24567
|
+
{
|
|
24568
|
+
code: "let choice = perform(@dvala.io.pick, [\"Red\", \"Green\", \"Blue\"])",
|
|
24569
|
+
noRun: true
|
|
24570
|
+
},
|
|
24571
|
+
{
|
|
24572
|
+
code: "let choice = perform(@dvala.io.pick, {items: [\"Red\", \"Green\", \"Blue\"], options: {prompt: \"Pick a color:\", default: 0}})",
|
|
24573
|
+
noRun: true
|
|
24574
|
+
},
|
|
24575
|
+
{
|
|
24576
|
+
code: "do\n let colors = [\"Red\", \"Green\", \"Blue\"];\n let idx = perform(@dvala.io.pick, colors);\n if idx != null then nth(colors, idx) else \"No selection\" end\nend",
|
|
24577
|
+
noRun: true
|
|
24578
|
+
}
|
|
24579
|
+
],
|
|
24552
24580
|
seeAlso: [
|
|
24553
24581
|
"-effect-dvala.io.read",
|
|
24554
24582
|
"-effect-dvala.io.confirm",
|
|
@@ -24594,7 +24622,13 @@ const standardEffects = {
|
|
|
24594
24622
|
}
|
|
24595
24623
|
},
|
|
24596
24624
|
variants: [{ argumentNames: ["question"] }, { argumentNames: ["question", "options"] }],
|
|
24597
|
-
examples: [
|
|
24625
|
+
examples: [{
|
|
24626
|
+
code: "if perform(@dvala.io.confirm, \"Delete all files?\") then \"Deleted\" else \"Cancelled\" end",
|
|
24627
|
+
noRun: true
|
|
24628
|
+
}, {
|
|
24629
|
+
code: "perform(@dvala.io.confirm, {question: \"Continue?\", options: {default: true}})",
|
|
24630
|
+
noRun: true
|
|
24631
|
+
}],
|
|
24598
24632
|
seeAlso: [
|
|
24599
24633
|
"-effect-dvala.io.read",
|
|
24600
24634
|
"-effect-dvala.io.pick",
|
|
@@ -24626,7 +24660,10 @@ const standardEffects = {
|
|
|
24626
24660
|
returns: { type: "string" },
|
|
24627
24661
|
args: {},
|
|
24628
24662
|
variants: [{ argumentNames: [] }],
|
|
24629
|
-
examples: [
|
|
24663
|
+
examples: [{
|
|
24664
|
+
code: "let input = perform(@dvala.io.readStdin); count(input)",
|
|
24665
|
+
noRun: true
|
|
24666
|
+
}],
|
|
24630
24667
|
seeAlso: [
|
|
24631
24668
|
"-effect-dvala.io.read",
|
|
24632
24669
|
"perform",
|
|
@@ -24866,7 +24903,13 @@ const standardEffects = {
|
|
|
24866
24903
|
description: "The number of milliseconds to sleep. Must be a non-negative number."
|
|
24867
24904
|
} },
|
|
24868
24905
|
variants: [{ argumentNames: ["ms"] }],
|
|
24869
|
-
examples: [
|
|
24906
|
+
examples: [{
|
|
24907
|
+
code: "do perform(@dvala.sleep, 1000); \"awake!\" end",
|
|
24908
|
+
noRun: true
|
|
24909
|
+
}, {
|
|
24910
|
+
code: "do perform(@dvala.io.print, \"waiting...\"); perform(@dvala.sleep, 500); perform(@dvala.io.print, \"done!\") end",
|
|
24911
|
+
noRun: true
|
|
24912
|
+
}],
|
|
24870
24913
|
seeAlso: [
|
|
24871
24914
|
"-effect-dvala.time.now",
|
|
24872
24915
|
"perform",
|
package/package.json
CHANGED