hobots 5.2.0 → 6.0.0
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/README.md +2 -1
- package/dist/index.cjs +19 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +17 -5
- package/dist/index.d.ts +17 -5
- package/dist/index.js +19 -5
- package/dist/index.js.map +1 -1
- package/docs/api-reference.md +1 -1
- package/docs/runs.md +6 -2
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -270,14 +270,17 @@ interface RunItemOptions extends RunItemImageOptions {
|
|
|
270
270
|
id?: string;
|
|
271
271
|
}
|
|
272
272
|
/**
|
|
273
|
-
* O item em processamento dentro de `items.each
|
|
273
|
+
* O item em processamento dentro de `items.each` — o único argumento do handler: o elemento
|
|
274
|
+
* em `value`, a posição em `index`, o desfecho (`succeeded`/`failed`/
|
|
274
275
|
* `occurrence`) com o `id` e o payload base já resolvidos, e o handle `step` da etapa do
|
|
275
276
|
* item (`warning`/`image`/`data`), e `data(...)` para ir guardando o payload do item sem
|
|
276
277
|
* decidir o desfecho. Sub-etapas: `hobots.step(...)` dentro do handler já
|
|
277
278
|
* aninha na etapa do item. Sem chamada explícita, o SDK decide: retornou → `succeeded`;
|
|
278
279
|
* lançou → `failed` com a mensagem do erro.
|
|
279
280
|
*/
|
|
280
|
-
interface RunItemHandle {
|
|
281
|
+
interface RunItemHandle<T = unknown> {
|
|
282
|
+
/** O elemento da lista — o mesmo em todas as tentativas. */
|
|
283
|
+
readonly value: T;
|
|
281
284
|
/** Posição do elemento na lista (0-based). */
|
|
282
285
|
readonly index: number;
|
|
283
286
|
/** Identidade do item: a resolvida por `options.id` ou, sem ela, uma gerada pelo SDK — a mesma em todas as tentativas. */
|
|
@@ -313,8 +316,13 @@ interface RunItemsEachOptions<T> {
|
|
|
313
316
|
* no elemento é erro do bot (lança e interrompe o loop).
|
|
314
317
|
*/
|
|
315
318
|
id?: string | readonly string[] | ((element: T, index: number) => string | number | null | undefined) | null;
|
|
316
|
-
/**
|
|
317
|
-
|
|
319
|
+
/**
|
|
320
|
+
* Atributos base do item (viram colunas no app) — presentes em qualquer desfecho, inclusive falha.
|
|
321
|
+
* Omitido: os campos do próprio elemento quando ele é um objeto simples (`{ id, cliente, … }`,
|
|
322
|
+
* cópia rasa); instância de classe, array e primitivo ficam sem payload base. Uma função substitui
|
|
323
|
+
* esse padrão (escolhe/renomeia as colunas); `false` desliga.
|
|
324
|
+
*/
|
|
325
|
+
payload?: ((element: T, index: number) => Record<string, unknown> | undefined) | false;
|
|
318
326
|
/** `op` da etapa de cada item no waterfall. Default: 'item'. */
|
|
319
327
|
op?: string;
|
|
320
328
|
/** Descrição da etapa de cada item. Default: o `id`, senão `#<posição>`. */
|
|
@@ -351,7 +359,11 @@ interface RunItemsEachResult {
|
|
|
351
359
|
/** Já concluídos neste trabalho (reexecução): não rodaram, mas contam no `total`. */
|
|
352
360
|
skipped: number;
|
|
353
361
|
}
|
|
354
|
-
|
|
362
|
+
/**
|
|
363
|
+
* Handler do `items.each` (6.0.0): `(item, index)` — o elemento em `item.value`; `index` (0-based,
|
|
364
|
+
* o mesmo que `item.index`) é opcional, declare só se usar.
|
|
365
|
+
*/
|
|
366
|
+
type RunItemsEachHandler<T> = (item: RunItemHandle<T>, index: number) => unknown;
|
|
355
367
|
/**
|
|
356
368
|
* Registro dos itens que a execução processou/gerou (a entrega do bot: notas
|
|
357
369
|
* fiscais baixadas, boletos emitidos...). Chamadas são síncronas — os itens são
|
package/dist/index.d.ts
CHANGED
|
@@ -270,14 +270,17 @@ interface RunItemOptions extends RunItemImageOptions {
|
|
|
270
270
|
id?: string;
|
|
271
271
|
}
|
|
272
272
|
/**
|
|
273
|
-
* O item em processamento dentro de `items.each
|
|
273
|
+
* O item em processamento dentro de `items.each` — o único argumento do handler: o elemento
|
|
274
|
+
* em `value`, a posição em `index`, o desfecho (`succeeded`/`failed`/
|
|
274
275
|
* `occurrence`) com o `id` e o payload base já resolvidos, e o handle `step` da etapa do
|
|
275
276
|
* item (`warning`/`image`/`data`), e `data(...)` para ir guardando o payload do item sem
|
|
276
277
|
* decidir o desfecho. Sub-etapas: `hobots.step(...)` dentro do handler já
|
|
277
278
|
* aninha na etapa do item. Sem chamada explícita, o SDK decide: retornou → `succeeded`;
|
|
278
279
|
* lançou → `failed` com a mensagem do erro.
|
|
279
280
|
*/
|
|
280
|
-
interface RunItemHandle {
|
|
281
|
+
interface RunItemHandle<T = unknown> {
|
|
282
|
+
/** O elemento da lista — o mesmo em todas as tentativas. */
|
|
283
|
+
readonly value: T;
|
|
281
284
|
/** Posição do elemento na lista (0-based). */
|
|
282
285
|
readonly index: number;
|
|
283
286
|
/** Identidade do item: a resolvida por `options.id` ou, sem ela, uma gerada pelo SDK — a mesma em todas as tentativas. */
|
|
@@ -313,8 +316,13 @@ interface RunItemsEachOptions<T> {
|
|
|
313
316
|
* no elemento é erro do bot (lança e interrompe o loop).
|
|
314
317
|
*/
|
|
315
318
|
id?: string | readonly string[] | ((element: T, index: number) => string | number | null | undefined) | null;
|
|
316
|
-
/**
|
|
317
|
-
|
|
319
|
+
/**
|
|
320
|
+
* Atributos base do item (viram colunas no app) — presentes em qualquer desfecho, inclusive falha.
|
|
321
|
+
* Omitido: os campos do próprio elemento quando ele é um objeto simples (`{ id, cliente, … }`,
|
|
322
|
+
* cópia rasa); instância de classe, array e primitivo ficam sem payload base. Uma função substitui
|
|
323
|
+
* esse padrão (escolhe/renomeia as colunas); `false` desliga.
|
|
324
|
+
*/
|
|
325
|
+
payload?: ((element: T, index: number) => Record<string, unknown> | undefined) | false;
|
|
318
326
|
/** `op` da etapa de cada item no waterfall. Default: 'item'. */
|
|
319
327
|
op?: string;
|
|
320
328
|
/** Descrição da etapa de cada item. Default: o `id`, senão `#<posição>`. */
|
|
@@ -351,7 +359,11 @@ interface RunItemsEachResult {
|
|
|
351
359
|
/** Já concluídos neste trabalho (reexecução): não rodaram, mas contam no `total`. */
|
|
352
360
|
skipped: number;
|
|
353
361
|
}
|
|
354
|
-
|
|
362
|
+
/**
|
|
363
|
+
* Handler do `items.each` (6.0.0): `(item, index)` — o elemento em `item.value`; `index` (0-based,
|
|
364
|
+
* o mesmo que `item.index`) é opcional, declare só se usar.
|
|
365
|
+
*/
|
|
366
|
+
type RunItemsEachHandler<T> = (item: RunItemHandle<T>, index: number) => unknown;
|
|
355
367
|
/**
|
|
356
368
|
* Registro dos itens que a execução processou/gerou (a entrega do bot: notas
|
|
357
369
|
* fiscais baixadas, boletos emitidos...). Chamadas são síncronas — os itens são
|
package/dist/index.js
CHANGED
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
|
|
5
5
|
// src/utils.ts
|
|
6
6
|
var SDK_NAME = "hobots";
|
|
7
|
-
var SDK_VERSION = true ? "
|
|
7
|
+
var SDK_VERSION = true ? "6.0.0" : "0.0.0-dev";
|
|
8
8
|
function isNode() {
|
|
9
9
|
return typeof process !== "undefined" && typeof process.versions?.node === "string";
|
|
10
10
|
}
|
|
@@ -1857,13 +1857,15 @@ function thrownMessage(error) {
|
|
|
1857
1857
|
return safeString(error);
|
|
1858
1858
|
}
|
|
1859
1859
|
var ItemHandle = class {
|
|
1860
|
-
constructor(index, id, step,
|
|
1860
|
+
constructor(value, index, id, step, basePayload2, sink) {
|
|
1861
|
+
this.value = value;
|
|
1861
1862
|
this.index = index;
|
|
1862
1863
|
this.step = step;
|
|
1863
|
-
this.basePayload =
|
|
1864
|
+
this.basePayload = basePayload2;
|
|
1864
1865
|
this.sink = sink;
|
|
1865
1866
|
this.id = id ?? uuid4();
|
|
1866
1867
|
}
|
|
1868
|
+
value;
|
|
1867
1869
|
index;
|
|
1868
1870
|
step;
|
|
1869
1871
|
basePayload;
|
|
@@ -1906,6 +1908,18 @@ var ItemHandle = class {
|
|
|
1906
1908
|
this.sink.report(status, message, Object.keys(merged).length > 0 ? merged : void 0, this.id, image3);
|
|
1907
1909
|
}
|
|
1908
1910
|
};
|
|
1911
|
+
function defaultPayload(element) {
|
|
1912
|
+
if (typeof element !== "object" || element === null) return void 0;
|
|
1913
|
+
const proto = Object.getPrototypeOf(element);
|
|
1914
|
+
if (proto !== Object.prototype && proto !== null) return void 0;
|
|
1915
|
+
const copy = { ...element };
|
|
1916
|
+
return Object.keys(copy).length > 0 ? copy : void 0;
|
|
1917
|
+
}
|
|
1918
|
+
function basePayload(spec, element, index) {
|
|
1919
|
+
if (spec === false) return void 0;
|
|
1920
|
+
if (spec === void 0) return defaultPayload(element);
|
|
1921
|
+
return spec(element, index);
|
|
1922
|
+
}
|
|
1909
1923
|
function field(element, name) {
|
|
1910
1924
|
if (typeof element !== "object" || element === null) return { present: false, value: void 0 };
|
|
1911
1925
|
const record = element;
|
|
@@ -1966,7 +1980,7 @@ async function eachItem(list, handler, options, sink) {
|
|
|
1966
1980
|
}
|
|
1967
1981
|
const description = options.description?.(element, index) ?? id ?? `#${index + 1}`;
|
|
1968
1982
|
const step = sink.startStep(options.op ?? "item", description);
|
|
1969
|
-
const handle = new ItemHandle(index, id, step, options.payload
|
|
1983
|
+
const handle = new ItemHandle(element, index, id, step, basePayload(options.payload, element, index), sink);
|
|
1970
1984
|
const current = index;
|
|
1971
1985
|
let attempts = 0;
|
|
1972
1986
|
let lastFailure;
|
|
@@ -1975,7 +1989,7 @@ async function eachItem(list, handler, options, sink) {
|
|
|
1975
1989
|
(attempt) => {
|
|
1976
1990
|
attempts = attempt;
|
|
1977
1991
|
if (attempt > 1) handle._nextAttempt(attempt);
|
|
1978
|
-
return sink.stepScope(step, async () => handler(
|
|
1992
|
+
return sink.stepScope(step, async () => handler(handle, current));
|
|
1979
1993
|
},
|
|
1980
1994
|
{
|
|
1981
1995
|
retries: totalRetries,
|