@sanoma-ai/workflows 0.0.0-stage → 0.1.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/LICENSE +105 -0
- package/README.md +493 -2
- package/dist/approvals.d.ts +46 -0
- package/dist/approvals.js +111 -0
- package/dist/approvals.js.map +1 -0
- package/dist/ast.d.ts +57 -0
- package/dist/ast.js +81 -0
- package/dist/ast.js.map +1 -0
- package/dist/call.d.ts +33 -0
- package/dist/call.js +402 -0
- package/dist/call.js.map +1 -0
- package/dist/client.d.ts +167 -0
- package/dist/client.js +400 -0
- package/dist/client.js.map +1 -0
- package/dist/config.d.ts +126 -0
- package/dist/config.js +247 -0
- package/dist/config.js.map +1 -0
- package/dist/credentials.d.ts +30 -0
- package/dist/credentials.js +193 -0
- package/dist/credentials.js.map +1 -0
- package/dist/cucumber.d.ts +64 -0
- package/dist/cucumber.js +158 -0
- package/dist/cucumber.js.map +1 -0
- package/dist/datafile.d.ts +62 -0
- package/dist/datafile.js +326 -0
- package/dist/datafile.js.map +1 -0
- package/dist/db.d.ts +58 -0
- package/dist/db.js +179 -0
- package/dist/db.js.map +1 -0
- package/dist/define.d.ts +205 -0
- package/dist/define.js +103 -0
- package/dist/define.js.map +1 -0
- package/dist/describe.d.ts +135 -0
- package/dist/describe.js +127 -0
- package/dist/describe.js.map +1 -0
- package/dist/drift.d.ts +75 -0
- package/dist/drift.js +90 -0
- package/dist/drift.js.map +1 -0
- package/dist/env.d.ts +49 -0
- package/dist/env.js +83 -0
- package/dist/env.js.map +1 -0
- package/dist/errors.d.ts +88 -0
- package/dist/errors.js +148 -0
- package/dist/errors.js.map +1 -0
- package/dist/expectations.d.ts +26 -0
- package/dist/expectations.js +137 -0
- package/dist/expectations.js.map +1 -0
- package/dist/fake.d.ts +55 -0
- package/dist/fake.js +87 -0
- package/dist/fake.js.map +1 -0
- package/dist/fill.d.ts +9 -0
- package/dist/fill.js +17 -0
- package/dist/fill.js.map +1 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.js +25 -0
- package/dist/index.js.map +1 -0
- package/dist/ledger.d.ts +217 -0
- package/dist/ledger.js +251 -0
- package/dist/ledger.js.map +1 -0
- package/dist/lint.d.ts +32 -0
- package/dist/lint.js +168 -0
- package/dist/lint.js.map +1 -0
- package/dist/log.d.ts +24 -0
- package/dist/log.js +83 -0
- package/dist/log.js.map +1 -0
- package/dist/op.d.ts +257 -0
- package/dist/op.js +188 -0
- package/dist/op.js.map +1 -0
- package/dist/outline.d.ts +179 -0
- package/dist/outline.js +506 -0
- package/dist/outline.js.map +1 -0
- package/dist/paths.d.ts +11 -0
- package/dist/paths.js +30 -0
- package/dist/paths.js.map +1 -0
- package/dist/plugin.d.ts +28 -0
- package/dist/plugin.js +25 -0
- package/dist/plugin.js.map +1 -0
- package/dist/policy.d.ts +114 -0
- package/dist/policy.js +60 -0
- package/dist/policy.js.map +1 -0
- package/dist/resource.d.ts +212 -0
- package/dist/resource.js +285 -0
- package/dist/resource.js.map +1 -0
- package/dist/resources.d.ts +62 -0
- package/dist/resources.js +197 -0
- package/dist/resources.js.map +1 -0
- package/dist/run.d.ts +87 -0
- package/dist/run.js +2 -0
- package/dist/run.js.map +1 -0
- package/dist/sandbox.d.ts +33 -0
- package/dist/sandbox.js +123 -0
- package/dist/sandbox.js.map +1 -0
- package/dist/scenario.d.ts +212 -0
- package/dist/scenario.js +1079 -0
- package/dist/scenario.js.map +1 -0
- package/dist/scenarios.d.ts +55 -0
- package/dist/scenarios.js +71 -0
- package/dist/scenarios.js.map +1 -0
- package/dist/shared.d.ts +61 -0
- package/dist/shared.js +77 -0
- package/dist/shared.js.map +1 -0
- package/dist/steps.d.ts +76 -0
- package/dist/steps.js +23 -0
- package/dist/steps.js.map +1 -0
- package/dist/version.d.ts +29 -0
- package/dist/version.js +76 -0
- package/dist/version.js.map +1 -0
- package/dist/worker.d.ts +34 -0
- package/dist/worker.js +219 -0
- package/dist/worker.js.map +1 -0
- package/oxlint.json +128 -0
- package/package.json +91 -3
- package/src/approvals.ts +157 -0
- package/src/ast.ts +115 -0
- package/src/call.ts +468 -0
- package/src/client.ts +534 -0
- package/src/config.ts +381 -0
- package/src/credentials.ts +211 -0
- package/src/cucumber.ts +230 -0
- package/src/datafile.ts +409 -0
- package/src/db.ts +197 -0
- package/src/define.ts +285 -0
- package/src/describe.ts +262 -0
- package/src/drift.ts +149 -0
- package/src/env.ts +122 -0
- package/src/errors.ts +202 -0
- package/src/expectations.ts +165 -0
- package/src/fake.ts +156 -0
- package/src/fill.ts +24 -0
- package/src/index.ts +120 -0
- package/src/ledger.ts +419 -0
- package/src/lint.ts +208 -0
- package/src/log.ts +82 -0
- package/src/op.ts +399 -0
- package/src/outline.ts +620 -0
- package/src/paths.ts +32 -0
- package/src/plugin.ts +37 -0
- package/src/policy.ts +139 -0
- package/src/resource.ts +447 -0
- package/src/resources.ts +256 -0
- package/src/run.ts +91 -0
- package/src/sandbox.ts +157 -0
- package/src/scenario.ts +1328 -0
- package/src/scenarios.ts +111 -0
- package/src/shared.ts +116 -0
- package/src/steps.ts +90 -0
- package/src/version.ts +86 -0
- package/src/worker.ts +253 -0
package/dist/cucumber.js
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import { Writable } from "node:stream";
|
|
2
|
+
import { supportCodeLibraryBuilder } from "@cucumber/cucumber";
|
|
3
|
+
import { runCucumber } from "@cucumber/cucumber/api";
|
|
4
|
+
import { NodeType } from "@cucumber/cucumber-expressions";
|
|
5
|
+
import { IdGenerator, TestStepResultStatus } from "@cucumber/messages";
|
|
6
|
+
import { Query } from "@cucumber/query";
|
|
7
|
+
/**
|
|
8
|
+
* Builds a support code library: the parameter types, then one step definition per expression,
|
|
9
|
+
* each handing its step to the World. Cucumber keeps one builder per process, so the library is
|
|
10
|
+
* built here, by hand, in one synchronous stretch (`reset`, register, `finalize`): building it
|
|
11
|
+
* again in the same process gives the same definitions, where a second `loadSupport` would
|
|
12
|
+
* import nothing new and find none.
|
|
13
|
+
*/
|
|
14
|
+
export function buildLibrary(parameterTypes, expressions) {
|
|
15
|
+
const builder = supportCodeLibraryBuilder;
|
|
16
|
+
builder.reset(process.cwd(), IdGenerator.uuid(), {
|
|
17
|
+
requireModules: [],
|
|
18
|
+
requirePaths: [],
|
|
19
|
+
importPaths: [],
|
|
20
|
+
loaders: [],
|
|
21
|
+
});
|
|
22
|
+
const { defineParameterType, defineStep, Before, BeforeStep } = builder.methods;
|
|
23
|
+
for (const { name, regexp, transformer } of parameterTypes) {
|
|
24
|
+
defineParameterType({ name, regexp: regexp, transformer, useForSnippets: false });
|
|
25
|
+
}
|
|
26
|
+
for (const expression of expressions)
|
|
27
|
+
defineStep(expression, stepCode(expression));
|
|
28
|
+
Before(function ({ pickle }) {
|
|
29
|
+
if (this.run.skips(pickle))
|
|
30
|
+
return "skipped";
|
|
31
|
+
this.begin(pickle);
|
|
32
|
+
return undefined;
|
|
33
|
+
});
|
|
34
|
+
BeforeStep(function ({ pickleStep }) {
|
|
35
|
+
this.current = pickleStep;
|
|
36
|
+
});
|
|
37
|
+
const library = builder.finalize();
|
|
38
|
+
// Cucumber checks a definition's code's `length` against what it passes: the expression's
|
|
39
|
+
// parameters, then the step's doc string or table, or else a callback. Its own parse of each
|
|
40
|
+
// expression says how many parameters it has.
|
|
41
|
+
for (const { code, expression } of library.stepDefinitions) {
|
|
42
|
+
Object.defineProperty(code, "length", {
|
|
43
|
+
value: countParameters(expression.ast) + 1,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
return library;
|
|
47
|
+
}
|
|
48
|
+
const countParameters = (node) => node.type === NodeType.parameter ? 1 : (node.nodes ?? []).reduce((n, child) => n + countParameters(child), 0);
|
|
49
|
+
/**
|
|
50
|
+
* A step definition's code. Cucumber passes the expression's values, then the step's doc string
|
|
51
|
+
* or table when it has one, then a callback: with one more argument than the parameters it took
|
|
52
|
+
* the callback of a step with no argument (the callback interface), and with two more, the
|
|
53
|
+
* argument of a step that has one (the promise interface). The World reads the argument from
|
|
54
|
+
* the pickle step, so the code answers both.
|
|
55
|
+
*/
|
|
56
|
+
function stepCode(expression) {
|
|
57
|
+
const code = function (...args) {
|
|
58
|
+
const parameters = code.length - 1;
|
|
59
|
+
const result = Promise.resolve()
|
|
60
|
+
.then(() => this.step(expression, args.slice(0, parameters), this.current))
|
|
61
|
+
.catch((err) => {
|
|
62
|
+
this.run.caught(err);
|
|
63
|
+
throw err;
|
|
64
|
+
});
|
|
65
|
+
if (args.length > parameters + 1)
|
|
66
|
+
return result;
|
|
67
|
+
const done = args.at(-1);
|
|
68
|
+
result.then((value) => done(null, value), (err) => done(err));
|
|
69
|
+
return undefined;
|
|
70
|
+
};
|
|
71
|
+
return code;
|
|
72
|
+
}
|
|
73
|
+
/** How each step of a run ended, by its pickle step's id; a step of a pickle that did not run has none. */
|
|
74
|
+
export function stepResults({ query }) {
|
|
75
|
+
const results = new Map();
|
|
76
|
+
for (const finished of query.findAllTestStepFinished()) {
|
|
77
|
+
const testStep = query.findTestStepBy(finished);
|
|
78
|
+
if (!testStep?.pickleStepId)
|
|
79
|
+
continue;
|
|
80
|
+
const { status, message, exception } = finished.testStepResult;
|
|
81
|
+
const why = exception?.message ?? message;
|
|
82
|
+
results.set(testStep.pickleStepId, {
|
|
83
|
+
status,
|
|
84
|
+
matches: query.findStepDefinitionsBy(testStep).map((d) => d.pattern.source),
|
|
85
|
+
...(why !== undefined && { message: why }),
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
return results;
|
|
89
|
+
}
|
|
90
|
+
/** A pickle's line: its examples row's, or its scenario's. */
|
|
91
|
+
export const lineOf = (report, pickle) => report.query.findLocationOf(pickle)?.line ?? 1;
|
|
92
|
+
/** A stream that drops what it is given: Cucumber's formatters and logger write nowhere. */
|
|
93
|
+
const sink = () => new Writable({
|
|
94
|
+
write(_chunk, _encoding, callback) {
|
|
95
|
+
callback();
|
|
96
|
+
},
|
|
97
|
+
});
|
|
98
|
+
/**
|
|
99
|
+
* A path as a glob that matches it alone: Cucumber globs each path it is given, and reads one
|
|
100
|
+
* whose name starts with `@` as a list of paths. Brackets escape what they can; brace
|
|
101
|
+
* expansion reads braces and commas before brackets, so those (and backslashes) match any
|
|
102
|
+
* character instead.
|
|
103
|
+
*/
|
|
104
|
+
const literal = (path) => path.replaceAll(/[*?[\]()+@]/g, "[$&]").replaceAll(/[{},\\]/g, "?");
|
|
105
|
+
/**
|
|
106
|
+
* Runs the feature files `files` (relative to `cwd`) with the library, serially, in this
|
|
107
|
+
* process, and reads back what happened. `line`, with a single file, runs only the scenario or
|
|
108
|
+
* examples row at that line. `makeWorld` makes each scenario's World, given the report so far
|
|
109
|
+
* (every file and pickle, read before the first scenario starts). A dry run matches the steps
|
|
110
|
+
* and runs none. A step's error that is a bug in code (`isBug`) is rethrown once the run is
|
|
111
|
+
* over, rather than reported as the step's failure.
|
|
112
|
+
*/
|
|
113
|
+
export async function runFeatures(library, makeWorld, { cwd, files, line, dryRun = false, isBug, }) {
|
|
114
|
+
const report = { query: new Query(), texts: new Map(), parseErrors: [] };
|
|
115
|
+
let bug;
|
|
116
|
+
const run = {
|
|
117
|
+
skips: (pickle) => line !== undefined && lineOf(report, pickle) !== line,
|
|
118
|
+
caught: (err) => {
|
|
119
|
+
if (isBug(err))
|
|
120
|
+
bug ??= err;
|
|
121
|
+
},
|
|
122
|
+
};
|
|
123
|
+
// Cucumber makes a scenario's World with `new`: a constructor that returns an object gives that object.
|
|
124
|
+
function World() {
|
|
125
|
+
return Object.assign(makeWorld(report), { run });
|
|
126
|
+
}
|
|
127
|
+
const configuration = {
|
|
128
|
+
sources: { defaultDialect: "en", paths: files.map(literal), names: [], tagExpression: "", order: "defined" },
|
|
129
|
+
support: { ...library, World },
|
|
130
|
+
runtime: {
|
|
131
|
+
dryRun,
|
|
132
|
+
failFast: false,
|
|
133
|
+
filterStacktraces: true,
|
|
134
|
+
parallel: 0,
|
|
135
|
+
retry: 0,
|
|
136
|
+
retryTagFilter: "",
|
|
137
|
+
strict: true,
|
|
138
|
+
worldParameters: {},
|
|
139
|
+
},
|
|
140
|
+
// Cucumber always formats to stdout, here a sink: `rerun` is the formatter that does least.
|
|
141
|
+
formats: { stdout: "rerun", files: {}, publish: false, options: {} },
|
|
142
|
+
};
|
|
143
|
+
await runCucumber(configuration, { cwd, stdout: sink(), stderr: sink(), env: {} }, (envelope) => {
|
|
144
|
+
report.query.update(envelope);
|
|
145
|
+
const { source, parseError } = envelope;
|
|
146
|
+
if (source)
|
|
147
|
+
report.texts.set(source.uri, source.data);
|
|
148
|
+
if (parseError) {
|
|
149
|
+
const { uri = "", location } = parseError.source;
|
|
150
|
+
report.parseErrors.push({ uri, ...(location && { line: location.line }), message: parseError.message });
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
if (bug !== undefined)
|
|
154
|
+
throw bug;
|
|
155
|
+
return report;
|
|
156
|
+
}
|
|
157
|
+
export { TestStepResultStatus as StepStatus };
|
|
158
|
+
//# sourceMappingURL=cucumber.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cucumber.js","sourceRoot":"","sources":["../src/cucumber.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,yBAAyB,EAAE,MAAM,oBAAoB,CAAC;AAC/D,OAAO,EAA8C,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACjG,OAAO,EAAsC,QAAQ,EAAE,MAAM,gCAAgC,CAAC;AAC9F,OAAO,EAAE,WAAW,EAAgC,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AACrG,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AA4BxC;;;;;;GAMG;AACH,MAAM,UAAU,YAAY,CAC1B,cAA4C,EAC5C,WAA6B;IAE7B,MAAM,OAAO,GAAG,yBAAyB,CAAC;IAC1C,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,WAAW,CAAC,I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B,MAAM,EAAE,IAAI;YACZ,eAAe,EAAE,EAAE;SACpB;QACD,4FAA4F;QAC5F,OAAO,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,EAAE;KACrE,CAAC;IACF,MAAM,WAAW,CAAC,aAAa,EAAE,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,GAAG,EAAE,EAAE,EAAE,EAAE,CAAC,QAAQ,EAAE,EAAE;QAC9F,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QAC9B,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,GAAG,QAAQ,CAAC;QACxC,IAAI,MAAM;YAAE,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC;QACtD,IAAI,UAAU,EAAE,CAAC;YACf,MAAM,EAAE,GAAG,GAAG,EAAE,EAAE,QAAQ,EAAE,GAAG,UAAU,CAAC,MAAM,CAAC;YACjD,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE,GAAG,EAAE,GAAG,CAAC,QAAQ,IAAI,EAAE,IAAI,EAAE,QAAQ,CAAC,IAAI,EAAE,CAAC,EAAE,OAAO,EAAE,UAAU,CAAC,OAAO,EAAE,CAAC,CAAC;QAC1G,CAAC;IACH,CAAC,CAAC,CAAC;IACH,IAAI,GAAG,KAAK,SAAS;QAAE,MAAM,GAAG,CAAC;IACjC,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,OAAO,EAAE,oBAAoB,IAAI,UAAU,EAAE,CAAC"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { Node } from "./ast.ts";
|
|
2
|
+
/** Something a data file may not hold, at UTF-16 offsets into its text. */
|
|
3
|
+
export interface DataFileProblem {
|
|
4
|
+
start: number;
|
|
5
|
+
end: number;
|
|
6
|
+
message: string;
|
|
7
|
+
}
|
|
8
|
+
/** A name in a data file that refers to a declared resource: one imported from a data file, or exported by this one. */
|
|
9
|
+
export declare class Reference {
|
|
10
|
+
readonly name: string;
|
|
11
|
+
constructor(name: string);
|
|
12
|
+
}
|
|
13
|
+
/** A value in a data file: a literal, or a reference to a declared resource. */
|
|
14
|
+
export type DataValue = null | boolean | number | string | Reference | DataValue[] | {
|
|
15
|
+
[field: string]: DataValue;
|
|
16
|
+
};
|
|
17
|
+
/** An `import { name } from "…"`: of a connector's constructors (`from "…/resources"`), or of another data file's resource. */
|
|
18
|
+
export interface DataFileImport {
|
|
19
|
+
kind: "constructors" | "file";
|
|
20
|
+
/** The specifier as written. */
|
|
21
|
+
source: string;
|
|
22
|
+
/** The name the other module exports. */
|
|
23
|
+
imported: string;
|
|
24
|
+
/** The name it has in this file. */
|
|
25
|
+
local: string;
|
|
26
|
+
start: number;
|
|
27
|
+
}
|
|
28
|
+
/** An `export const name = vendor.type({ … })`. */
|
|
29
|
+
export interface DataFileExport {
|
|
30
|
+
name: string;
|
|
31
|
+
/** The local name of the constructors it calls (`github`). */
|
|
32
|
+
vendor: string;
|
|
33
|
+
type: string;
|
|
34
|
+
desired: {
|
|
35
|
+
[field: string]: DataValue;
|
|
36
|
+
};
|
|
37
|
+
/** The `export const` statement. */
|
|
38
|
+
start: number;
|
|
39
|
+
end: number;
|
|
40
|
+
}
|
|
41
|
+
export interface DataFile {
|
|
42
|
+
imports: DataFileImport[];
|
|
43
|
+
/** Each `export const` whose value is in the subset. */
|
|
44
|
+
exports: DataFileExport[];
|
|
45
|
+
/** Every name an `export const` declares, its value in the subset or not. */
|
|
46
|
+
declared: string[];
|
|
47
|
+
problems: DataFileProblem[];
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Reads a data file's program without running it: its imports, each `export const` resource
|
|
51
|
+
* with its fields evaluated, and everything outside the data-file subset as a problem that says
|
|
52
|
+
* what to write instead.
|
|
53
|
+
*
|
|
54
|
+
* The subset: named imports, from a connector's `…/resources` entry or a `.ts` data file;
|
|
55
|
+
* `export const <name> = <vendor>.<type>({ … })`, one per statement, its argument built of
|
|
56
|
+
* strings (template literals without `${}` too), numbers, booleans, null, objects and arrays,
|
|
57
|
+
* and names of resources this file declares or imports; and `export default [a, b]`.
|
|
58
|
+
*
|
|
59
|
+
* `root` is the directory relative imports must stay in: by default the nearest `resources/`
|
|
60
|
+
* directory above `filename`, else the file's own.
|
|
61
|
+
*/
|
|
62
|
+
export declare function readDataFile(program: Node, filename: string, root?: string): DataFile;
|
package/dist/datafile.js
ADDED
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
import { basename, dirname, join } from "node:path";
|
|
2
|
+
import { inside, nearestDir, RELATIVE } from "./paths.js";
|
|
3
|
+
/** A name in a data file that refers to a declared resource: one imported from a data file, or exported by this one. */
|
|
4
|
+
export class Reference {
|
|
5
|
+
name;
|
|
6
|
+
constructor(name) {
|
|
7
|
+
this.name = name;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
/** A connector's constructors entry: a package specifier that ends in `/resources`. */
|
|
11
|
+
const CONSTRUCTORS = /^(@[a-z0-9-~][a-z0-9-._~]*\/)?[a-z0-9-~][a-z0-9-._~]*\/resources$/;
|
|
12
|
+
const SHAPE = "a data file holds only imports, `export const <name> = <vendor>.<type>({ … })` and `export default [ … ]`";
|
|
13
|
+
const IMPORTS = "import resource constructors from a connector's resources entry " +
|
|
14
|
+
'(`import { github } from "@sanoma-ai/connector-github/resources"`) ' +
|
|
15
|
+
'and resources from other data files (`import { site } from "./github.ts"`)';
|
|
16
|
+
const VALUES = "write a string, number, boolean, null, object or array, or name a declared resource";
|
|
17
|
+
/**
|
|
18
|
+
* Reads a data file's program without running it: its imports, each `export const` resource
|
|
19
|
+
* with its fields evaluated, and everything outside the data-file subset as a problem that says
|
|
20
|
+
* what to write instead.
|
|
21
|
+
*
|
|
22
|
+
* The subset: named imports, from a connector's `…/resources` entry or a `.ts` data file;
|
|
23
|
+
* `export const <name> = <vendor>.<type>({ … })`, one per statement, its argument built of
|
|
24
|
+
* strings (template literals without `${}` too), numbers, booleans, null, objects and arrays,
|
|
25
|
+
* and names of resources this file declares or imports; and `export default [a, b]`.
|
|
26
|
+
*
|
|
27
|
+
* `root` is the directory relative imports must stay in: by default the nearest `resources/`
|
|
28
|
+
* directory above `filename`, else the file's own.
|
|
29
|
+
*/
|
|
30
|
+
export function readDataFile(program, filename, root = nearestDir(filename, ["resources"])) {
|
|
31
|
+
const problems = [];
|
|
32
|
+
const fail = (node, message) => problems.push({ start: node.start, end: node.end, message });
|
|
33
|
+
const imports = [];
|
|
34
|
+
const exports = [];
|
|
35
|
+
// Names a refused import or declaration binds: reported once, where they are bound.
|
|
36
|
+
const refused = new Set();
|
|
37
|
+
// Imports and top-level names first, each once: imports are hoisted, and a reference may name
|
|
38
|
+
// a resource declared further down. An unexported const is refused where it is declared, not
|
|
39
|
+
// again where it is used.
|
|
40
|
+
const bound = new Set();
|
|
41
|
+
const bind = (id) => {
|
|
42
|
+
if (bound.has(id.name))
|
|
43
|
+
fail(id, `${id.name} is declared twice in this file: give each its own name`);
|
|
44
|
+
bound.add(id.name);
|
|
45
|
+
};
|
|
46
|
+
const declared = new Set();
|
|
47
|
+
for (const s of program.body) {
|
|
48
|
+
if (s.type === "ImportDeclaration") {
|
|
49
|
+
for (const sp of s.specifiers)
|
|
50
|
+
bind(sp.local);
|
|
51
|
+
readImport(s);
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
const decl = s.type === "ExportNamedDeclaration" ? s.declaration : s;
|
|
55
|
+
if (decl?.type !== "VariableDeclaration")
|
|
56
|
+
continue;
|
|
57
|
+
for (const d of decl.declarations) {
|
|
58
|
+
if (d.id.type !== "Identifier")
|
|
59
|
+
continue;
|
|
60
|
+
bind(d.id);
|
|
61
|
+
(decl === s ? refused : declared).add(d.id.name);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
for (const s of program.body) {
|
|
65
|
+
switch (s.type) {
|
|
66
|
+
case "ImportDeclaration":
|
|
67
|
+
break;
|
|
68
|
+
case "ExportNamedDeclaration":
|
|
69
|
+
readExport(s);
|
|
70
|
+
break;
|
|
71
|
+
case "ExportDefaultDeclaration":
|
|
72
|
+
readDefault(s);
|
|
73
|
+
break;
|
|
74
|
+
case "ExportAllDeclaration":
|
|
75
|
+
fail(s, `export * is not allowed in a data file: ${SHAPE}`);
|
|
76
|
+
break;
|
|
77
|
+
case "VariableDeclaration": {
|
|
78
|
+
const name = s.declarations[0]?.id?.name;
|
|
79
|
+
fail(s, name === undefined
|
|
80
|
+
? `an unexported declaration is not allowed in a data file: ${SHAPE}`
|
|
81
|
+
: `\`${s.kind} ${name}\` is not allowed in a data file: export it as a resource, \`export const ${name} = <vendor>.<type>({ … })\`, or write its value where it is used`);
|
|
82
|
+
break;
|
|
83
|
+
}
|
|
84
|
+
default:
|
|
85
|
+
fail(s, `${describe(s)} is not allowed in a data file: ${SHAPE}`);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
function readImport(s) {
|
|
89
|
+
const spec = s.source.value;
|
|
90
|
+
if (s.importKind === "type") {
|
|
91
|
+
fail(s, "`import type` is not allowed in a data file: it holds values only, and the constructors type them");
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
const refusal = whyRefused(spec);
|
|
95
|
+
if (refusal) {
|
|
96
|
+
fail(s.source, `import "${spec}" is not allowed in a data file: ${refusal}`);
|
|
97
|
+
for (const sp of s.specifiers)
|
|
98
|
+
refused.add(sp.local.name);
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
if (!s.specifiers.length) {
|
|
102
|
+
fail(s, `import "${spec}" is not allowed in a data file: it imports nothing, and a data file runs no code`);
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
for (const sp of s.specifiers) {
|
|
106
|
+
if (sp.type !== "ImportSpecifier") {
|
|
107
|
+
const how = sp.type === "ImportNamespaceSpecifier" ? `import * as ${sp.local.name}` : `import ${sp.local.name}`;
|
|
108
|
+
fail(sp, `${how} is not allowed in a data file: import the names you use, \`import { name } from "${spec}"\``);
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
if (sp.importKind === "type") {
|
|
112
|
+
fail(sp, "`type` imports are not allowed in a data file: it holds values only, and the constructors type them");
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
const imported = sp.imported.name ?? sp.imported.value;
|
|
116
|
+
const kind = RELATIVE.test(spec) ? "file" : "constructors";
|
|
117
|
+
imports.push({ kind, source: spec, imported, local: sp.local.name, start: sp.start });
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
/** Why an import's specifier is not allowed in a data file, or undefined when it is. */
|
|
121
|
+
function whyRefused(spec) {
|
|
122
|
+
if (!RELATIVE.test(spec))
|
|
123
|
+
return CONSTRUCTORS.test(spec) ? undefined : IMPORTS;
|
|
124
|
+
if (!spec.endsWith(".ts"))
|
|
125
|
+
return "name the data file with its `.ts` extension";
|
|
126
|
+
if (!inside(root, join(dirname(filename), spec))) {
|
|
127
|
+
return `it reaches outside ${basename(root)}/; import only other data files`;
|
|
128
|
+
}
|
|
129
|
+
return undefined;
|
|
130
|
+
}
|
|
131
|
+
function readExport(s) {
|
|
132
|
+
const decl = s.declaration;
|
|
133
|
+
if (!decl) {
|
|
134
|
+
fail(s, s.source
|
|
135
|
+
? `export … from "${s.source.value}" is not allowed in a data file: import what you reference, and export only resources declared here`
|
|
136
|
+
: "export { … } is not allowed in a data file: export each resource where it is declared, `export const name = <vendor>.<type>({ … })`");
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
if (decl.type !== "VariableDeclaration") {
|
|
140
|
+
fail(s, `${describe(decl)} is not allowed in a data file: ${SHAPE}`);
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
if (decl.kind !== "const") {
|
|
144
|
+
fail(s, `\`export ${decl.kind}\` is not allowed in a data file: use \`export const\``);
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
if (decl.declarations.length !== 1) {
|
|
148
|
+
fail(s, "declare one resource per `export const`");
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
const [d] = decl.declarations;
|
|
152
|
+
if (d.id.type !== "Identifier") {
|
|
153
|
+
fail(d.id, "an `export const` names one resource: `export const name = <vendor>.<type>({ … })`");
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
const name = d.id.name;
|
|
157
|
+
// A second declaration of the name was reported where it is bound.
|
|
158
|
+
if (exports.some((e) => e.name === name))
|
|
159
|
+
return;
|
|
160
|
+
const init = d.init;
|
|
161
|
+
const callee = init?.type === "CallExpression" ? init.callee : undefined;
|
|
162
|
+
if (callee?.type !== "MemberExpression" ||
|
|
163
|
+
callee.computed ||
|
|
164
|
+
callee.object.type !== "Identifier" ||
|
|
165
|
+
callee.property.type !== "Identifier") {
|
|
166
|
+
fail(init ?? d, `export const ${name} must be a resource constructor call, \`<vendor>.<type>({ … })\`, with <vendor> imported from a connector's resources entry`);
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
const vendor = callee.object.name;
|
|
170
|
+
const type = callee.property.name;
|
|
171
|
+
if (refused.has(vendor))
|
|
172
|
+
return;
|
|
173
|
+
if (imports.find((i) => i.local === vendor)?.kind !== "constructors") {
|
|
174
|
+
fail(callee.object, `${vendor} is not a connector's resource constructors: import it from the connector's resources entry, \`import { ${vendor} } from "@sanoma-ai/connector-${vendor}/resources"\``);
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
const [arg] = init.arguments;
|
|
178
|
+
if (init.arguments.length !== 1 || arg.type !== "ObjectExpression") {
|
|
179
|
+
fail(init, `${vendor}.${type} takes one object literal: \`${vendor}.${type}({ … })\``);
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
const desired = value(arg);
|
|
183
|
+
if (desired !== undefined) {
|
|
184
|
+
exports.push({ name, vendor, type, desired: desired, start: s.start, end: s.end });
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
function readDefault(s) {
|
|
188
|
+
const list = s.declaration;
|
|
189
|
+
if (list.type !== "ArrayExpression") {
|
|
190
|
+
fail(list, "export default must list this file's resources: `export default [a, b]`");
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
for (const el of list.elements) {
|
|
194
|
+
if (el?.type !== "Identifier") {
|
|
195
|
+
fail(el ?? list, "export default must list this file's resources by name: `export default [a, b]`");
|
|
196
|
+
}
|
|
197
|
+
else if (!declared.has(el.name)) {
|
|
198
|
+
fail(el, `${el.name} is not declared in this file: export default lists this file's resources`);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
/** The value an expression stands for, or undefined (with a problem) when the subset has none. */
|
|
203
|
+
function value(node) {
|
|
204
|
+
switch (node.type) {
|
|
205
|
+
case "Literal":
|
|
206
|
+
if (node.regex)
|
|
207
|
+
return refuse(node, "a regular expression is not allowed in a data file: write it as a string");
|
|
208
|
+
if (node.bigint !== undefined && node.bigint !== null)
|
|
209
|
+
return refuse(node, "a bigint is not allowed in a data file: write a number, or a string");
|
|
210
|
+
return node.value;
|
|
211
|
+
case "TemplateLiteral":
|
|
212
|
+
if (node.expressions.length) {
|
|
213
|
+
return refuse(node, "a template with `${…}` is not allowed in a data file: write the string out");
|
|
214
|
+
}
|
|
215
|
+
return node.quasis[0].value.cooked;
|
|
216
|
+
case "UnaryExpression":
|
|
217
|
+
if (node.operator === "-" && node.argument.type === "Literal" && typeof node.argument.value === "number") {
|
|
218
|
+
return -node.argument.value;
|
|
219
|
+
}
|
|
220
|
+
return refuse(node, `\`${node.operator}\` is not allowed in a data file: write the value out`);
|
|
221
|
+
case "ArrayExpression": {
|
|
222
|
+
const items = [];
|
|
223
|
+
let ok = true;
|
|
224
|
+
for (const el of node.elements) {
|
|
225
|
+
const item = el === null
|
|
226
|
+
? refuse(node, "an empty array slot is not allowed in a data file: write null")
|
|
227
|
+
: el.type === "SpreadElement"
|
|
228
|
+
? refuse(el, "a spread is not allowed in a data file: write the items out, so the reader sees each")
|
|
229
|
+
: value(el);
|
|
230
|
+
if (item === undefined)
|
|
231
|
+
ok = false;
|
|
232
|
+
else
|
|
233
|
+
items.push(item);
|
|
234
|
+
}
|
|
235
|
+
return ok ? items : undefined;
|
|
236
|
+
}
|
|
237
|
+
case "ObjectExpression": {
|
|
238
|
+
const fields = new Map();
|
|
239
|
+
let ok = true;
|
|
240
|
+
for (const p of node.properties) {
|
|
241
|
+
const field = property(p);
|
|
242
|
+
if (field && fields.has(field[0]))
|
|
243
|
+
fail(p, `${field[0]} is given twice: give each field once`);
|
|
244
|
+
if (!field || fields.has(field[0]))
|
|
245
|
+
ok = false;
|
|
246
|
+
else
|
|
247
|
+
fields.set(...field);
|
|
248
|
+
}
|
|
249
|
+
// fromEntries makes each field an own property, even one named `__proto__`.
|
|
250
|
+
return ok ? Object.fromEntries(fields) : undefined;
|
|
251
|
+
}
|
|
252
|
+
case "Identifier":
|
|
253
|
+
return reference(node);
|
|
254
|
+
case "MemberExpression": {
|
|
255
|
+
let base = node;
|
|
256
|
+
while (base.type === "MemberExpression")
|
|
257
|
+
base = base.object;
|
|
258
|
+
if (base.type === "Identifier" && base.name === "process") {
|
|
259
|
+
return refuse(node, "process is not allowed in a data file: it is read without running, so it cannot read the environment; write the value out, and leave secrets to drivers");
|
|
260
|
+
}
|
|
261
|
+
return refuse(node, "member access is not allowed in a data file: write the value out, or name the resource itself (`site`), not one of its fields");
|
|
262
|
+
}
|
|
263
|
+
case "CallExpression":
|
|
264
|
+
return refuse(node, node.callee.type === "MemberExpression" &&
|
|
265
|
+
node.callee.object.type === "Identifier" &&
|
|
266
|
+
imports.some((i) => i.kind === "constructors" && i.local === node.callee.object.name)
|
|
267
|
+
? "a resource is declared at the top of a data file: give it its own `export const` and name it here"
|
|
268
|
+
: "a call is not allowed in a data file: write the value out; the reader never runs code");
|
|
269
|
+
case "NewExpression":
|
|
270
|
+
return refuse(node, "`new` is not allowed in a data file: write the value out (a date as an ISO 8601 string)");
|
|
271
|
+
case "ArrowFunctionExpression":
|
|
272
|
+
case "FunctionExpression":
|
|
273
|
+
return refuse(node, "a function is not allowed in a data file: a field holds a value, and code belongs in a workflow");
|
|
274
|
+
case "TSAsExpression":
|
|
275
|
+
case "TSSatisfiesExpression":
|
|
276
|
+
case "TSTypeAssertion":
|
|
277
|
+
case "TSNonNullExpression":
|
|
278
|
+
return refuse(node, "a type assertion is not allowed in a data file: leave it out; the constructor types the value");
|
|
279
|
+
default:
|
|
280
|
+
return refuse(node, `${describe(node)} is not allowed in a data file: ${VALUES}`);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
function property(p) {
|
|
284
|
+
if (p.type === "SpreadElement") {
|
|
285
|
+
return refuse(p, "a spread is not allowed in a data file: write the fields out, so the reader sees each");
|
|
286
|
+
}
|
|
287
|
+
if (p.kind !== "init" || p.method) {
|
|
288
|
+
return refuse(p, "a method or accessor is not allowed in a data file: a field holds a value");
|
|
289
|
+
}
|
|
290
|
+
if (p.computed)
|
|
291
|
+
return refuse(p.key, "a computed key is not allowed in a data file: write the field's name");
|
|
292
|
+
const key = p.key.type === "Identifier" ? p.key.name : p.key.type === "Literal" ? String(p.key.value) : undefined;
|
|
293
|
+
if (key === undefined)
|
|
294
|
+
return refuse(p.key, "write the field's name, or a string");
|
|
295
|
+
const v = value(p.value);
|
|
296
|
+
return v === undefined ? undefined : [key, v];
|
|
297
|
+
}
|
|
298
|
+
function reference(node) {
|
|
299
|
+
const name = node.name;
|
|
300
|
+
if (name === "undefined")
|
|
301
|
+
return refuse(node, "undefined is not allowed in a data file: leave the field out, or write null");
|
|
302
|
+
const imported = imports.find((i) => i.local === name);
|
|
303
|
+
if (imported?.kind === "constructors") {
|
|
304
|
+
return refuse(node, `${name} is a connector's resource constructors, not a resource: name a declared resource`);
|
|
305
|
+
}
|
|
306
|
+
if (imported || declared.has(name))
|
|
307
|
+
return new Reference(name);
|
|
308
|
+
if (refused.has(name))
|
|
309
|
+
return undefined;
|
|
310
|
+
return refuse(node, `${name} is not a resource this file declares or imports from a data file: write the value out, or import the resource`);
|
|
311
|
+
}
|
|
312
|
+
function refuse(node, message) {
|
|
313
|
+
fail(node, message);
|
|
314
|
+
return undefined;
|
|
315
|
+
}
|
|
316
|
+
return { imports, exports, declared: [...declared], problems };
|
|
317
|
+
}
|
|
318
|
+
/** A node's kind, for a message: `a function declaration`, `an if statement`. */
|
|
319
|
+
function describe(node) {
|
|
320
|
+
const words = String(node.type)
|
|
321
|
+
.replace(/^TS/, "TypeScript ")
|
|
322
|
+
.replace(/([a-z])([A-Z])/g, "$1 $2")
|
|
323
|
+
.toLowerCase();
|
|
324
|
+
return `${/^[aeiou]/.test(words) ? "an" : "a"} ${words}`;
|
|
325
|
+
}
|
|
326
|
+
//# sourceMappingURL=datafile.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"datafile.js","sourceRoot":"","sources":["../src/datafile.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEpD,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAc1D,wHAAwH;AACxH,MAAM,OAAO,SAAS;IACX,IAAI,CAAS;IACtB,YAAY,IAAY;QACtB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;CACF;AAsCD,uFAAuF;AACvF,MAAM,YAAY,GAAG,mEAAmE,CAAC;AAEzF,MAAM,KAAK,GACT,2GAA2G,CAAC;AAC9G,MAAM,OAAO,GACX,kEAAkE;IAClE,qEAAqE;IACrE,4EAA4E,CAAC;AAC/E,MAAM,MAAM,GAAG,qFAAqF,CAAC;AAErG;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,YAAY,CAC1B,OAAa,EACb,QAAgB,EAChB,IAAI,GAAW,UAAU,CAA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AAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,KAAK,EAAE,CAAC;AAC3D,CAAC"}
|
package/dist/db.d.ts
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { DBOSClient } from "@dbos-inc/dbos-sdk";
|
|
2
|
+
import { Client, Pool } from "pg";
|
|
3
|
+
/** A connection or a pool: what the queries take. */
|
|
4
|
+
export type Db = Pick<Pool | Client, "query">;
|
|
5
|
+
/** Where the credentials set from the app live. */
|
|
6
|
+
export declare const CREDENTIALS_TABLE = "sanoma_credentials";
|
|
7
|
+
/** Where the Postgres ledger keeps its records. */
|
|
8
|
+
export declare const LEDGER_TABLE = "sanoma_ledger";
|
|
9
|
+
/** The Postgres error code of `err`, or an empty string when it has none. */
|
|
10
|
+
export declare const pgCode: (err: unknown) => string;
|
|
11
|
+
/** True for the failure of a create that another process won: what was to be made is there. */
|
|
12
|
+
export declare const madeAlready: (err: unknown) => boolean;
|
|
13
|
+
/**
|
|
14
|
+
* A pool on the config's database for `what` (a word for the messages). An idle connection that
|
|
15
|
+
* drops (Postgres restarted) is replaced on the next query; unheard, it would end the process.
|
|
16
|
+
*/
|
|
17
|
+
export declare function openPool(databaseUrl: string, what: string): Pool;
|
|
18
|
+
/**
|
|
19
|
+
* What every DBOS handle on the config's database is given (`DBOS.setConfig`, `dbosClient`): DBOS
|
|
20
|
+
* is told not to set Postgres's `idle_in_transaction_session_timeout` on each connection of its
|
|
21
|
+
* pool. It sends that `SET` from the pool's `connect` event without awaiting it (dbos-sdk 5.2.11,
|
|
22
|
+
* dist/src/system_database.js:691), so the pool hands the connection out while it runs: two
|
|
23
|
+
* queries at once on one client, which pg deprecates. `prepareDatabase` sets the same 60 s guard
|
|
24
|
+
* on the database instead. Remove the switch when DBOS awaits its `SET`.
|
|
25
|
+
*/
|
|
26
|
+
export declare const DBOS_DATABASE_OPTIONS: {
|
|
27
|
+
readonly systemDatabaseIdleTransactionTimeoutMs: 0;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* A DBOS client of the app `applicationName` on the database at `databaseUrl`, as every client of
|
|
31
|
+
* the runtime, its tests and `@sanoma-ai/testing` make one (`DBOS_DATABASE_OPTIONS`).
|
|
32
|
+
*/
|
|
33
|
+
export declare const dbosClient: (databaseUrl: string, applicationName?: string) => Promise<DBOSClient>;
|
|
34
|
+
/** A pool opened on first use, once its database is prepared, and ended by `close`. */
|
|
35
|
+
export interface LazyPool {
|
|
36
|
+
db(): Promise<Pool>;
|
|
37
|
+
close(): Promise<void>;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* A pool for `what` on the database at `databaseUrl`, opened on the first `db()` once the
|
|
41
|
+
* database is prepared (`prepareDatabase`). A preparation that fails lets the pool go, so the
|
|
42
|
+
* next `db()` tries again. `close` ends the pool, for good: a `db()` after it is refused.
|
|
43
|
+
*/
|
|
44
|
+
export declare function lazyPool(databaseUrl: string, what: string): LazyPool;
|
|
45
|
+
/**
|
|
46
|
+
* Makes the database at `databaseUrl` ready for the runtime, once per process and URL: the
|
|
47
|
+
* database itself and DBOS's tables when they are not there yet (as a worker's launch makes
|
|
48
|
+
* them; credentials may be set, and a ledger read, before any worker has run), then the
|
|
49
|
+
* credentials and ledger tables, and its idle-transaction timeout (`guardIdleTransactions`).
|
|
50
|
+
* Two processes preparing one database both succeed. A
|
|
51
|
+
* preparation that fails is forgotten, so the next call tries again.
|
|
52
|
+
*/
|
|
53
|
+
export declare function prepareDatabase(databaseUrl: string): Promise<void>;
|
|
54
|
+
/**
|
|
55
|
+
* Runs `ddl` (`CREATE TABLE IF NOT EXISTS`, and the like) on `db`. Two processes racing to create
|
|
56
|
+
* the same table both succeed; any other failure names the `what` table, with its cause.
|
|
57
|
+
*/
|
|
58
|
+
export declare function createTable(db: Db, ddl: string, what: string): Promise<void>;
|