Files
jogos_matheus/scripts/CLAUDE.md
T
2026-09-23 12:29:08 -03:00

1.7 KiB

Scripts

Reusable JS logic loaded via libService.loadScript('script-key'). All scripts run on Mozilla Rhino (ES5) — the same engine and constraints as endpoints and panel inline scripts. See root CLAUDE.md for the full ES5 rules.

What's NOT available in scripts

  • No engine object (that's panel/process-only).
  • No params request object (that's endpoint-only).
  • No browser or Node globals (window, require, process, etc.).

Services like vProcessInstanceService, vConfigService, and libs like db, http are available and injected the same way as everywhere else.

Two patterns

Process / task scripts — top-level execution

Scripts triggered directly by a process task or scheduler. Code runs at the top level, no export needed.

var db    = libService.loadScript('db');
var banco = new db(db.VITRUVIO_DATASOURCE);

var result = banco.queryForList("SELECT ...", {});
// do work...

Library scripts — object literal export

Reusable libs meant to be loaded by other scripts, endpoints, or panels. Wrap everything in a ({...}) object literal — this is the value returned by libService.loadScript().

({
  versao: 1.0,
  nome: 'My Library',

  myFunction: function(params) {
    var db    = libService.loadScript('db');
    var banco = new db(db.VITRUVIO_DATASOURCE);
    // ...
    return result;
  }
})

The caller then uses it as:

var myLib = libService.loadScript('my-lib');
myLib.myFunction({ foo: 'bar' });

vitruvio.json registration

"scripts": [
  {
    "key": "my-lib",
    "name": "My Library",
    "path": "scripts/my-lib.js",
    "domain": "USUARIO"
  }
]

domain is either "SISTEMA" (system-level) or "USUARIO" (user-level). Default to "USUARIO".