@sealcode/jdd 0.3.1 → 0.3.2
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/@types/component-arguments/image.d.ts +2 -0
- package/@types/component-arguments/list.d.ts +3 -1
- package/lib/component-arguments/image.js +17 -11
- package/lib/component-arguments/image.js.map +1 -1
- package/lib/component-arguments/list.js +11 -2
- package/lib/component-arguments/list.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { JDDContext } from "..";
|
|
2
2
|
import { File as FileArgument } from "./file";
|
|
3
3
|
export declare class Image extends FileArgument {
|
|
4
|
+
private example_image_promises;
|
|
4
5
|
getTypeName(): string;
|
|
6
|
+
setExampleImages(paths: string[]): this;
|
|
5
7
|
getExampleValue(context: JDDContext): Promise<string>;
|
|
6
8
|
}
|
|
@@ -2,9 +2,11 @@ import { JDDContext } from "..";
|
|
|
2
2
|
import { ComponentArgument } from "./component-argument";
|
|
3
3
|
export declare class List<T> extends ComponentArgument<Array<T>> {
|
|
4
4
|
item_type: ComponentArgument<T>;
|
|
5
|
-
|
|
5
|
+
example_count: number | null;
|
|
6
|
+
constructor(item_type: ComponentArgument<T>, example_count?: number | null);
|
|
6
7
|
getTypeName(): string;
|
|
7
8
|
getEmptyValue(): never[];
|
|
9
|
+
getExampleCount(): number;
|
|
8
10
|
getExampleValue(context: JDDContext): Promise<T[]>;
|
|
9
11
|
countWords(value: Array<T>): number;
|
|
10
12
|
parseFormInput(context: JDDContext, input: unknown, arg_name: string): Promise<T[] | null>;
|
|
@@ -16,27 +16,33 @@ exports.Image = void 0;
|
|
|
16
16
|
const locreq_1 = __importDefault(require("locreq"));
|
|
17
17
|
const file_1 = require("./file");
|
|
18
18
|
const locreq = (0, locreq_1.default)(__dirname);
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
"image5.jpg": null,
|
|
24
|
-
};
|
|
19
|
+
const default_example_image_promises = Object.fromEntries(["image1.jpg", "image3.jpg", "image4.jpg", "image5.jpg"].map((key) => [
|
|
20
|
+
locreq.resolve(`resources/${key}`),
|
|
21
|
+
null,
|
|
22
|
+
]));
|
|
25
23
|
class Image extends file_1.File {
|
|
24
|
+
constructor() {
|
|
25
|
+
super(...arguments);
|
|
26
|
+
this.example_image_promises = default_example_image_promises;
|
|
27
|
+
}
|
|
26
28
|
getTypeName() {
|
|
27
29
|
return "image";
|
|
28
30
|
}
|
|
31
|
+
setExampleImages(paths) {
|
|
32
|
+
this.example_image_promises = Object.fromEntries(paths.map((path) => [path, null]));
|
|
33
|
+
return this;
|
|
34
|
+
}
|
|
29
35
|
getExampleValue(context) {
|
|
30
36
|
return __awaiter(this, void 0, void 0, function* () {
|
|
31
|
-
const keys = Object.keys(example_image_promises);
|
|
37
|
+
const keys = Object.keys(this.example_image_promises);
|
|
32
38
|
const key = keys[Math.floor(Math.random() * keys.length)];
|
|
33
|
-
if (!example_image_promises[key]) {
|
|
34
|
-
example_image_promises[key] = context.encode_file({
|
|
39
|
+
if (!this.example_image_promises[key]) {
|
|
40
|
+
this.example_image_promises[key] = context.encode_file({
|
|
35
41
|
type: "path",
|
|
36
|
-
path:
|
|
42
|
+
path: key,
|
|
37
43
|
}, true);
|
|
38
44
|
}
|
|
39
|
-
return example_image_promises[key];
|
|
45
|
+
return this.example_image_promises[key];
|
|
40
46
|
});
|
|
41
47
|
}
|
|
42
48
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"image.js","sourceRoot":"","sources":["../../src/component-arguments/image.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,oDAA6B;AAE7B,iCAA8C;AAC9C,MAAM,MAAM,GAAG,IAAA,gBAAO,EAAC,SAAS,CAAC,CAAC;AAElC,
|
|
1
|
+
{"version":3,"file":"image.js","sourceRoot":"","sources":["../../src/component-arguments/image.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,oDAA6B;AAE7B,iCA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9 +13,10 @@ exports.List = void 0;
|
|
|
13
13
|
const ts_predicates_1 = require("@sealcode/ts-predicates");
|
|
14
14
|
const component_argument_1 = require("./component-argument");
|
|
15
15
|
class List extends component_argument_1.ComponentArgument {
|
|
16
|
-
constructor(item_type) {
|
|
16
|
+
constructor(item_type, example_count = null) {
|
|
17
17
|
super();
|
|
18
18
|
this.item_type = item_type;
|
|
19
|
+
this.example_count = example_count;
|
|
19
20
|
item_type.parent_argument = this;
|
|
20
21
|
}
|
|
21
22
|
getTypeName() {
|
|
@@ -24,6 +25,14 @@ class List extends component_argument_1.ComponentArgument {
|
|
|
24
25
|
getEmptyValue() {
|
|
25
26
|
return [];
|
|
26
27
|
}
|
|
28
|
+
getExampleCount() {
|
|
29
|
+
if (this.example_count === null) {
|
|
30
|
+
return Math.floor(Math.random() * 5);
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
return this.example_count;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
27
36
|
getExampleValue(context) {
|
|
28
37
|
const _super = Object.create(null, {
|
|
29
38
|
getExampleValue: { get: () => super.getExampleValue }
|
|
@@ -33,7 +42,7 @@ class List extends component_argument_1.ComponentArgument {
|
|
|
33
42
|
return _super.getExampleValue.call(this, context);
|
|
34
43
|
}
|
|
35
44
|
else {
|
|
36
|
-
const count =
|
|
45
|
+
const count = this.getExampleCount();
|
|
37
46
|
const result = [];
|
|
38
47
|
for (let i = 0; i < count; i++) {
|
|
39
48
|
result.push(this.item_type.getExampleValue(context));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"list.js","sourceRoot":"","sources":["../../src/component-arguments/list.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2DAAyD;AAGzD,
|
|
1
|
+
{"version":3,"file":"list.js","sourceRoot":"","sources":["../../src/component-arguments/list.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2DAAyD;AAGzD,6DAAyD;AAEzD,MAAa,IAAQ,SAAQ,sCAA2B;IACvD,YAC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