hobots 5.1.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 +3 -1
- package/dist/index.cjs +25 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +27 -7
- package/dist/index.d.ts +27 -7
- package/dist/index.js +25 -6
- 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,13 +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
|
-
* item (`warning`/`image`/`data`)
|
|
276
|
+
* item (`warning`/`image`/`data`), e `data(...)` para ir guardando o payload do item sem
|
|
277
|
+
* decidir o desfecho. Sub-etapas: `hobots.step(...)` dentro do handler já
|
|
276
278
|
* aninha na etapa do item. Sem chamada explícita, o SDK decide: retornou → `succeeded`;
|
|
277
279
|
* lançou → `failed` com a mensagem do erro.
|
|
278
280
|
*/
|
|
279
|
-
interface RunItemHandle {
|
|
281
|
+
interface RunItemHandle<T = unknown> {
|
|
282
|
+
/** O elemento da lista — o mesmo em todas as tentativas. */
|
|
283
|
+
readonly value: T;
|
|
280
284
|
/** Posição do elemento na lista (0-based). */
|
|
281
285
|
readonly index: number;
|
|
282
286
|
/** Identidade do item: a resolvida por `options.id` ou, sem ela, uma gerada pelo SDK — a mesma em todas as tentativas. */
|
|
@@ -289,7 +293,14 @@ interface RunItemHandle {
|
|
|
289
293
|
readonly status: RunItemStatus | undefined;
|
|
290
294
|
/** Tentativa em curso (1-based) — o handler pode ler para logar. */
|
|
291
295
|
readonly attempt: number;
|
|
292
|
-
/**
|
|
296
|
+
/**
|
|
297
|
+
* Guarda atributos do item sem registrar desfecho — vai mesclando a cada chamada (chave repetida:
|
|
298
|
+
* a última vence). Entra em qualquer desfecho, inclusive nos implícitos (handler retornou →
|
|
299
|
+
* `succeeded`; lançou → `failed`), entre o payload base de `options.payload` e o payload da
|
|
300
|
+
* chamada de desfecho. Uma nova tentativa começa do zero. Depois do desfecho só acumula: nada é reenviado.
|
|
301
|
+
*/
|
|
302
|
+
data(payload: Record<string, unknown>): void;
|
|
303
|
+
/** Item processado com sucesso. `payload` é mesclado sobre o payload base e o de `item.data`. */
|
|
293
304
|
succeeded(payload?: Record<string, unknown>, options?: RunItemImageOptions): void;
|
|
294
305
|
/** Falha sem lançar — o loop segue igual; a etapa vira `error` com o motivo. A imagem vai no item. */
|
|
295
306
|
failed(message: string, payload?: Record<string, unknown>, options?: RunItemImageOptions): void;
|
|
@@ -305,8 +316,13 @@ interface RunItemsEachOptions<T> {
|
|
|
305
316
|
* no elemento é erro do bot (lança e interrompe o loop).
|
|
306
317
|
*/
|
|
307
318
|
id?: string | readonly string[] | ((element: T, index: number) => string | number | null | undefined) | null;
|
|
308
|
-
/**
|
|
309
|
-
|
|
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;
|
|
310
326
|
/** `op` da etapa de cada item no waterfall. Default: 'item'. */
|
|
311
327
|
op?: string;
|
|
312
328
|
/** Descrição da etapa de cada item. Default: o `id`, senão `#<posição>`. */
|
|
@@ -343,7 +359,11 @@ interface RunItemsEachResult {
|
|
|
343
359
|
/** Já concluídos neste trabalho (reexecução): não rodaram, mas contam no `total`. */
|
|
344
360
|
skipped: number;
|
|
345
361
|
}
|
|
346
|
-
|
|
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;
|
|
347
367
|
/**
|
|
348
368
|
* Registro dos itens que a execução processou/gerou (a entrega do bot: notas
|
|
349
369
|
* fiscais baixadas, boletos emitidos...). Chamadas são síncronas — os itens são
|
package/dist/index.d.ts
CHANGED
|
@@ -270,13 +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
|
-
* item (`warning`/`image`/`data`)
|
|
276
|
+
* item (`warning`/`image`/`data`), e `data(...)` para ir guardando o payload do item sem
|
|
277
|
+
* decidir o desfecho. Sub-etapas: `hobots.step(...)` dentro do handler já
|
|
276
278
|
* aninha na etapa do item. Sem chamada explícita, o SDK decide: retornou → `succeeded`;
|
|
277
279
|
* lançou → `failed` com a mensagem do erro.
|
|
278
280
|
*/
|
|
279
|
-
interface RunItemHandle {
|
|
281
|
+
interface RunItemHandle<T = unknown> {
|
|
282
|
+
/** O elemento da lista — o mesmo em todas as tentativas. */
|
|
283
|
+
readonly value: T;
|
|
280
284
|
/** Posição do elemento na lista (0-based). */
|
|
281
285
|
readonly index: number;
|
|
282
286
|
/** Identidade do item: a resolvida por `options.id` ou, sem ela, uma gerada pelo SDK — a mesma em todas as tentativas. */
|
|
@@ -289,7 +293,14 @@ interface RunItemHandle {
|
|
|
289
293
|
readonly status: RunItemStatus | undefined;
|
|
290
294
|
/** Tentativa em curso (1-based) — o handler pode ler para logar. */
|
|
291
295
|
readonly attempt: number;
|
|
292
|
-
/**
|
|
296
|
+
/**
|
|
297
|
+
* Guarda atributos do item sem registrar desfecho — vai mesclando a cada chamada (chave repetida:
|
|
298
|
+
* a última vence). Entra em qualquer desfecho, inclusive nos implícitos (handler retornou →
|
|
299
|
+
* `succeeded`; lançou → `failed`), entre o payload base de `options.payload` e o payload da
|
|
300
|
+
* chamada de desfecho. Uma nova tentativa começa do zero. Depois do desfecho só acumula: nada é reenviado.
|
|
301
|
+
*/
|
|
302
|
+
data(payload: Record<string, unknown>): void;
|
|
303
|
+
/** Item processado com sucesso. `payload` é mesclado sobre o payload base e o de `item.data`. */
|
|
293
304
|
succeeded(payload?: Record<string, unknown>, options?: RunItemImageOptions): void;
|
|
294
305
|
/** Falha sem lançar — o loop segue igual; a etapa vira `error` com o motivo. A imagem vai no item. */
|
|
295
306
|
failed(message: string, payload?: Record<string, unknown>, options?: RunItemImageOptions): void;
|
|
@@ -305,8 +316,13 @@ interface RunItemsEachOptions<T> {
|
|
|
305
316
|
* no elemento é erro do bot (lança e interrompe o loop).
|
|
306
317
|
*/
|
|
307
318
|
id?: string | readonly string[] | ((element: T, index: number) => string | number | null | undefined) | null;
|
|
308
|
-
/**
|
|
309
|
-
|
|
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;
|
|
310
326
|
/** `op` da etapa de cada item no waterfall. Default: 'item'. */
|
|
311
327
|
op?: string;
|
|
312
328
|
/** Descrição da etapa de cada item. Default: o `id`, senão `#<posição>`. */
|
|
@@ -343,7 +359,11 @@ interface RunItemsEachResult {
|
|
|
343
359
|
/** Já concluídos neste trabalho (reexecução): não rodaram, mas contam no `total`. */
|
|
344
360
|
skipped: number;
|
|
345
361
|
}
|
|
346
|
-
|
|
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;
|
|
347
367
|
/**
|
|
348
368
|
* Registro dos itens que a execução processou/gerou (a entrega do bot: notas
|
|
349
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;
|
|
@@ -1873,6 +1875,10 @@ var ItemHandle = class {
|
|
|
1873
1875
|
reported = false;
|
|
1874
1876
|
status;
|
|
1875
1877
|
attempt = 1;
|
|
1878
|
+
accumulated = {};
|
|
1879
|
+
data(payload) {
|
|
1880
|
+
Object.assign(this.accumulated, payload);
|
|
1881
|
+
}
|
|
1876
1882
|
succeeded(payload, options) {
|
|
1877
1883
|
this.record("succeeded", void 0, payload, options?.image);
|
|
1878
1884
|
}
|
|
@@ -1889,6 +1895,7 @@ var ItemHandle = class {
|
|
|
1889
1895
|
this.attempt = attempt;
|
|
1890
1896
|
this.reported = false;
|
|
1891
1897
|
this.status = void 0;
|
|
1898
|
+
this.accumulated = {};
|
|
1892
1899
|
if (this.step && (this.step.status === "error" || this.step.status === "warning")) {
|
|
1893
1900
|
this.step._setStatus("ok");
|
|
1894
1901
|
this.step._deleteData("message");
|
|
@@ -1897,10 +1904,22 @@ var ItemHandle = class {
|
|
|
1897
1904
|
record(status, message, payload, image3) {
|
|
1898
1905
|
this.reported = true;
|
|
1899
1906
|
this.status = status;
|
|
1900
|
-
const merged = { ...this.basePayload ?? {}, ...payload ?? {} };
|
|
1907
|
+
const merged = { ...this.basePayload ?? {}, ...this.accumulated, ...payload ?? {} };
|
|
1901
1908
|
this.sink.report(status, message, Object.keys(merged).length > 0 ? merged : void 0, this.id, image3);
|
|
1902
1909
|
}
|
|
1903
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
|
+
}
|
|
1904
1923
|
function field(element, name) {
|
|
1905
1924
|
if (typeof element !== "object" || element === null) return { present: false, value: void 0 };
|
|
1906
1925
|
const record = element;
|
|
@@ -1961,7 +1980,7 @@ async function eachItem(list, handler, options, sink) {
|
|
|
1961
1980
|
}
|
|
1962
1981
|
const description = options.description?.(element, index) ?? id ?? `#${index + 1}`;
|
|
1963
1982
|
const step = sink.startStep(options.op ?? "item", description);
|
|
1964
|
-
const handle = new ItemHandle(index, id, step, options.payload
|
|
1983
|
+
const handle = new ItemHandle(element, index, id, step, basePayload(options.payload, element, index), sink);
|
|
1965
1984
|
const current = index;
|
|
1966
1985
|
let attempts = 0;
|
|
1967
1986
|
let lastFailure;
|
|
@@ -1970,7 +1989,7 @@ async function eachItem(list, handler, options, sink) {
|
|
|
1970
1989
|
(attempt) => {
|
|
1971
1990
|
attempts = attempt;
|
|
1972
1991
|
if (attempt > 1) handle._nextAttempt(attempt);
|
|
1973
|
-
return sink.stepScope(step, async () => handler(
|
|
1992
|
+
return sink.stepScope(step, async () => handler(handle, current));
|
|
1974
1993
|
},
|
|
1975
1994
|
{
|
|
1976
1995
|
retries: totalRetries,
|