@mojir/dvala 0.0.15 → 0.0.16

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.
Files changed (2) hide show
  1. package/dist/cli/cli.js +123 -1
  2. package/package.json +3 -1
package/dist/cli/cli.js CHANGED
@@ -477,7 +477,7 @@ function findAllOccurrences(input, pattern) {
477
477
  }
478
478
  //#endregion
479
479
  //#region package.json
480
- var version = "0.0.15";
480
+ var version = "0.0.16";
481
481
  //#endregion
482
482
  //#region src/typeGuards/string.ts
483
483
  function isString(value, options = {}) {
@@ -24481,6 +24481,128 @@ const standardEffects = {
24481
24481
  "-effect-dvala.io.read-stdin",
24482
24482
  "-effect-dvala.io.print",
24483
24483
  "-effect-dvala.io.println",
24484
+ "-effect-dvala.io.pick",
24485
+ "-effect-dvala.io.confirm",
24486
+ "perform",
24487
+ "effect"
24488
+ ]
24489
+ }
24490
+ },
24491
+ "dvala.io.pick": {
24492
+ handler: (args, k, sourceCodeInfo) => {
24493
+ const items = args[0];
24494
+ const options = args[1];
24495
+ if (!Array.isArray(items)) throw new DvalaError(`dvala.io.pick: first argument must be an array, got ${typeof items}`, sourceCodeInfo);
24496
+ if (items.length === 0) throw new DvalaError("dvala.io.pick: items array must not be empty", sourceCodeInfo);
24497
+ 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);
24498
+ let promptMessage;
24499
+ let defaultIndex;
24500
+ if (options !== void 0) {
24501
+ if (typeof options !== "object" || options === null || Array.isArray(options)) throw new DvalaError(`dvala.io.pick: second argument must be an object, got ${typeof options}`, sourceCodeInfo);
24502
+ const opts = options;
24503
+ if (opts["prompt"] !== void 0) {
24504
+ if (typeof opts["prompt"] !== "string") throw new DvalaError("dvala.io.pick: options.prompt must be a string", sourceCodeInfo);
24505
+ promptMessage = opts["prompt"];
24506
+ }
24507
+ if (opts["default"] !== void 0) {
24508
+ if (typeof opts["default"] !== "number" || !Number.isInteger(opts["default"])) throw new DvalaError("dvala.io.pick: options.default must be an integer", sourceCodeInfo);
24509
+ defaultIndex = opts["default"];
24510
+ if (defaultIndex < 0 || defaultIndex >= items.length) throw new DvalaError(`dvala.io.pick: options.default (${defaultIndex}) is out of bounds for array of length ${items.length}`, sourceCodeInfo);
24511
+ }
24512
+ }
24513
+ if (typeof globalThis.prompt === "function") {
24514
+ const listLines = items.map((item, i) => `${i}: ${item}`).join("\n");
24515
+ const message = `${promptMessage ?? "Choose an item:"}${defaultIndex !== void 0 ? ` [default: ${defaultIndex}]` : ""}\n${listLines}`;
24516
+ const result = globalThis.prompt(message);
24517
+ if (result === null) return {
24518
+ type: "Value",
24519
+ value: null,
24520
+ k
24521
+ };
24522
+ const trimmed = result.trim();
24523
+ if (trimmed === "") return {
24524
+ type: "Value",
24525
+ value: defaultIndex !== void 0 ? defaultIndex : null,
24526
+ k
24527
+ };
24528
+ const parsed = Number(trimmed);
24529
+ if (!Number.isInteger(parsed) || parsed < 0 || parsed >= items.length) throw new DvalaError(`dvala.io.pick: invalid selection "${trimmed}"`, sourceCodeInfo);
24530
+ return {
24531
+ type: "Value",
24532
+ value: parsed,
24533
+ k
24534
+ };
24535
+ }
24536
+ throw new DvalaError("dvala.io.pick is not supported in this environment. In Node.js, register a \"dvala.io.pick\" host handler.", sourceCodeInfo);
24537
+ },
24538
+ arity: {
24539
+ min: 1,
24540
+ max: 2
24541
+ },
24542
+ docs: {
24543
+ category: "effect",
24544
+ description: "Presents a numbered list of items and asks the user to choose one. In browsers uses `window.prompt()`. In Node.js, register a host handler. Resumes with the index of the chosen item, or `null` if the user cancels.",
24545
+ returns: { type: ["integer", "null"] },
24546
+ args: {
24547
+ items: {
24548
+ type: "array",
24549
+ description: "Non-empty array of strings to display."
24550
+ },
24551
+ options: {
24552
+ type: "object",
24553
+ description: "Optional settings: `prompt` (string label) and `default` (integer index to use when the user submits an empty input)."
24554
+ }
24555
+ },
24556
+ variants: [{ argumentNames: ["items"] }, { argumentNames: ["items", "options"] }],
24557
+ examples: ["effect(dvala.io.pick)"],
24558
+ seeAlso: [
24559
+ "-effect-dvala.io.read-line",
24560
+ "-effect-dvala.io.confirm",
24561
+ "perform",
24562
+ "effect"
24563
+ ]
24564
+ }
24565
+ },
24566
+ "dvala.io.confirm": {
24567
+ handler: (args, k, sourceCodeInfo) => {
24568
+ const question = args[0];
24569
+ const options = args[1];
24570
+ if (typeof question !== "string") throw new DvalaError(`dvala.io.confirm: first argument must be a string, got ${typeof question}`, sourceCodeInfo);
24571
+ if (options !== void 0) {
24572
+ if (typeof options !== "object" || options === null || Array.isArray(options)) throw new DvalaError(`dvala.io.confirm: second argument must be an object, got ${typeof options}`, sourceCodeInfo);
24573
+ const opts = options;
24574
+ if (opts["default"] !== void 0 && typeof opts["default"] !== "boolean") throw new DvalaError("dvala.io.confirm: options.default must be a boolean", sourceCodeInfo);
24575
+ }
24576
+ if (typeof globalThis.confirm === "function") return {
24577
+ type: "Value",
24578
+ value: globalThis.confirm(question),
24579
+ k
24580
+ };
24581
+ throw new DvalaError("dvala.io.confirm is not supported in this environment. In Node.js, register a \"dvala.io.confirm\" host handler.", sourceCodeInfo);
24582
+ },
24583
+ arity: {
24584
+ min: 1,
24585
+ max: 2
24586
+ },
24587
+ docs: {
24588
+ category: "effect",
24589
+ description: "Asks the user a yes/no question. In browsers uses `window.confirm()` and returns `true` (OK) or `false` (Cancel). In Node.js, register a host handler. The optional `default` hints the preferred answer to host handlers (e.g. for rendering `[Y/n]` in a CLI), but has no effect on the browser implementation.",
24590
+ returns: { type: "boolean" },
24591
+ args: {
24592
+ question: {
24593
+ type: "string",
24594
+ description: "The yes/no question to present."
24595
+ },
24596
+ options: {
24597
+ type: "object",
24598
+ description: "Optional settings: `default` (boolean, hints the preferred answer for host handlers)."
24599
+ }
24600
+ },
24601
+ variants: [{ argumentNames: ["question"] }, { argumentNames: ["question", "options"] }],
24602
+ examples: ["effect(dvala.io.confirm)"],
24603
+ seeAlso: [
24604
+ "-effect-dvala.io.read-line",
24605
+ "-effect-dvala.io.pick",
24484
24606
  "perform",
24485
24607
  "effect"
24486
24608
  ]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mojir/dvala",
3
- "version": "0.0.15",
3
+ "version": "0.0.16",
4
4
  "description": "dvala",
5
5
  "author": "Albert Mojir",
6
6
  "license": "MIT",
@@ -138,7 +138,9 @@
138
138
  "dvala": "node ./dist/cli/cli.js",
139
139
  "dev": "npx serve docs -p 9901",
140
140
  "test:e2e": "npx playwright test",
141
+ "test:e2e:prod": "E2E_BASE_URL=https://mojir.github.io/dvala npx playwright test",
141
142
  "test:e2e:headed": "npx playwright test --headed",
143
+ "test:e2e:prod:headed": "E2E_BASE_URL=https://mojir.github.io/dvala npx playwright test --headed",
142
144
  "lcov": "open-cli ./coverage/index.html",
143
145
  "mcp:inspect": "npx @modelcontextprotocol/inspector node ./dist/mcp-server/server.js"
144
146
  },