@factorialco/fcode-cli 3.4.0 → 3.5.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
CHANGED
|
@@ -20,7 +20,7 @@ $ npm install -g @factorialco/fcode-cli
|
|
|
20
20
|
$ fcode COMMAND
|
|
21
21
|
running command...
|
|
22
22
|
$ fcode (--version)
|
|
23
|
-
@factorialco/fcode-cli/3.
|
|
23
|
+
@factorialco/fcode-cli/3.5.0 linux-x64 node-v22.22.3
|
|
24
24
|
$ fcode --help [COMMAND]
|
|
25
25
|
USAGE
|
|
26
26
|
$ fcode COMMAND
|
|
@@ -6,6 +6,7 @@ const resource_checker_1 = require("../services/resource-checker");
|
|
|
6
6
|
const promise_1 = require("../utils/promise");
|
|
7
7
|
const types_1 = require("./types");
|
|
8
8
|
const variable_warnings_1 = require("../utils/variable-warnings");
|
|
9
|
+
const file_parameter_warnings_1 = require("../utils/file-parameter-warnings");
|
|
9
10
|
const global_1 = require("../config/global");
|
|
10
11
|
const settings_1 = require("../config/settings");
|
|
11
12
|
class ResourcePusher {
|
|
@@ -64,7 +65,10 @@ class ResourcePusher {
|
|
|
64
65
|
async pushResource(resource) {
|
|
65
66
|
try {
|
|
66
67
|
if (this._repository._repositoryName === 'processes') {
|
|
67
|
-
const
|
|
68
|
+
const process = resource;
|
|
69
|
+
// Only the processes being pushed are named, so each gets fixed by whoever next touches it.
|
|
70
|
+
(0, file_parameter_warnings_1.warnDeprecatedFileFields)(process.slug, (0, file_parameter_warnings_1.deprecatedFileFields)(process.script?.parametersSchema));
|
|
71
|
+
const updatedProcess = await this._fcodeGraphQLClient.pushProcess(process);
|
|
68
72
|
return this._repository.save(updatedProcess);
|
|
69
73
|
}
|
|
70
74
|
if (this._repository._repositoryName === 'modules') {
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export interface DeprecatedFileField {
|
|
2
|
+
/** Dotted path of the property inside the schema's `properties`, e.g. `dumpFile` or `upload.file`. */
|
|
3
|
+
path: string;
|
|
4
|
+
/** Extensions taken from `ui:options.accept`, the value `x-fcode-file.accept` should carry. */
|
|
5
|
+
accept: Array<string>;
|
|
6
|
+
}
|
|
7
|
+
export declare function deprecatedFileFields(schema: any): Array<DeprecatedFileField>;
|
|
8
|
+
export declare function warnDeprecatedFileFields(processSlug: string, fields: Array<DeprecatedFileField>): void;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.deprecatedFileFields = deprecatedFileFields;
|
|
4
|
+
exports.warnDeprecatedFileFields = warnDeprecatedFileFields;
|
|
5
|
+
const color_1 = require("@oclif/color");
|
|
6
|
+
const cli_1 = require("./cli");
|
|
7
|
+
// A file parameter is declared with `x-fcode-file`. `"ui:widget": "file"` is an rjsf presentation
|
|
8
|
+
// key, so a property that only has the widget is still recognised as a file for now, but that
|
|
9
|
+
// fallback is deprecated and will go.
|
|
10
|
+
function deprecatedFileFields(schema) {
|
|
11
|
+
const fields = [];
|
|
12
|
+
collect(schema, [], fields);
|
|
13
|
+
return fields;
|
|
14
|
+
}
|
|
15
|
+
function collect(node, parents, fields) {
|
|
16
|
+
const properties = node?.properties;
|
|
17
|
+
if (!isObject(properties)) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
for (const [key, property] of Object.entries(properties)) {
|
|
21
|
+
if (!isObject(property)) {
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
const path = [...parents, key];
|
|
25
|
+
if (property.ui?.['ui:widget'] === 'file' && property['x-fcode-file'] == undefined) {
|
|
26
|
+
fields.push({ path: path.join('.'), accept: acceptList(property.ui['ui:options']?.accept) });
|
|
27
|
+
}
|
|
28
|
+
collect(property, path, fields);
|
|
29
|
+
collect(property.items, path, fields);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
function acceptList(accept) {
|
|
33
|
+
const values = Array.isArray(accept) ? accept : typeof accept === 'string' ? accept.split(',') : [];
|
|
34
|
+
return values.map((value) => String(value).trim()).filter((value) => value !== '');
|
|
35
|
+
}
|
|
36
|
+
function isObject(value) {
|
|
37
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
38
|
+
}
|
|
39
|
+
// Naming extensions is the habit worth teaching: accept is what tells a Factorial One agent what the
|
|
40
|
+
// parameter takes. An empty list is still offered, so a field that really takes any file can say so.
|
|
41
|
+
function warnDeprecatedFileFields(processSlug, fields) {
|
|
42
|
+
for (const field of fields) {
|
|
43
|
+
const fix = field.accept.length > 0
|
|
44
|
+
? `Add "x-fcode-file": { "accept": ${extensionList(field.accept)} } to it in parametersSchema.json ` +
|
|
45
|
+
`(or { "accept": [] } if it really takes any file).`
|
|
46
|
+
: `Add "x-fcode-file" to it in parametersSchema.json, listing the extensions it takes, ` +
|
|
47
|
+
`e.g. { "accept": [".csv", ".xlsx"] }: they tell Factorial One what the parameter takes. ` +
|
|
48
|
+
`If it really takes any file, declare that with { "accept": [] }.`;
|
|
49
|
+
cli_1.default.log(color_1.default.yellow(`⚠️ '${processSlug}': parameter '${field.path}' is a file only through "ui:widget": "file", which is deprecated ` +
|
|
50
|
+
`for declaring a file and will stop working. ${fix}`));
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
function extensionList(extensions) {
|
|
54
|
+
return `[${extensions.map((extension) => JSON.stringify(extension)).join(', ')}]`;
|
|
55
|
+
}
|
package/oclif.manifest.json
CHANGED