@sealcode/jdd 0.3.1 → 0.3.3
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/component-arguments.d.ts +1 -0
- package/@types/component-arguments/image.d.ts +2 -0
- package/@types/component-arguments/list.d.ts +3 -1
- package/@types/component-arguments/url.d.ts +12 -0
- package/lib/component-arguments/component-arguments.js +3 -1
- package/lib/component-arguments/component-arguments.js.map +1 -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/lib/component-arguments/url.js +36 -0
- package/lib/component-arguments/url.js.map +1 -0
- 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>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { JDDContext } from "../jdd-context";
|
|
2
|
+
import { ComponentArgument } from "./component-argument";
|
|
3
|
+
import { MaybePromise } from "../utils/util-types";
|
|
4
|
+
export declare class URL extends ComponentArgument<string> {
|
|
5
|
+
readonly urlType: Readonly<"relative" | "absolute">;
|
|
6
|
+
constructor(urlType: Readonly<"relative" | "absolute">);
|
|
7
|
+
getTypeName(): string;
|
|
8
|
+
getEmptyValue(): string;
|
|
9
|
+
getExampleValue(): "/example" | "https://example.com";
|
|
10
|
+
countWords(): number;
|
|
11
|
+
parseFormInput(_: JDDContext, input: unknown): MaybePromise<string | string[] | null>;
|
|
12
|
+
}
|
|
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.Structured = exports.ShortText = exports.Markdown = exports.List = exports.File = exports.Image = exports.Enum = void 0;
|
|
17
|
+
exports.URL = exports.Structured = exports.ShortText = exports.Markdown = exports.List = exports.File = exports.Image = exports.Enum = void 0;
|
|
18
18
|
var enum_1 = require("./enum");
|
|
19
19
|
Object.defineProperty(exports, "Enum", { enumerable: true, get: function () { return enum_1.Enum; } });
|
|
20
20
|
var image_1 = require("./image");
|
|
@@ -30,4 +30,6 @@ Object.defineProperty(exports, "ShortText", { enumerable: true, get: function ()
|
|
|
30
30
|
var structured_1 = require("./structured");
|
|
31
31
|
Object.defineProperty(exports, "Structured", { enumerable: true, get: function () { return structured_1.Structured; } });
|
|
32
32
|
__exportStar(require("./table"), exports);
|
|
33
|
+
var url_1 = require("./url");
|
|
34
|
+
Object.defineProperty(exports, "URL", { enumerable: true, get: function () { return url_1.URL; } });
|
|
33
35
|
//# sourceMappingURL=component-arguments.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"component-arguments.js","sourceRoot":"","sources":["../../src/component-arguments/component-arguments.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,+BAA8B;AAArB,4FAAA,IAAI,OAAA;AACb,iCAAgC;AAAvB,8FAAA,KAAK,OAAA;AACd,+BAA8B;AAArB,4FAAA,IAAI,OAAA;AACb,+BAA8B;AAArB,4FAAA,IAAI,OAAA;AACb,uCAA0D;AAAjD,oGAAA,gBAAgB,OAAY;AACrC,2CAAyC;AAAhC,uGAAA,SAAS,OAAA;AAClB,2CAA0C;AAAjC,wGAAA,UAAU,OAAA;AACnB,0CAAwB"}
|
|
1
|
+
{"version":3,"file":"component-arguments.js","sourceRoot":"","sources":["../../src/component-arguments/component-arguments.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,+BAA8B;AAArB,4FAAA,IAAI,OAAA;AACb,iCAAgC;AAAvB,8FAAA,KAAK,OAAA;AACd,+BAA8B;AAArB,4FAAA,IAAI,OAAA;AACb,+BAA8B;AAArB,4FAAA,IAAI,OAAA;AACb,uCAA0D;AAAjD,oGAAA,gBAAgB,OAAY;AACrC,2CAAyC;AAAhC,uGAAA,SAAS,OAAA;AAClB,2CAA0C;AAAjC,wGAAA,UAAU,OAAA;AACnB,0CAAwB;AACxB,6BAA4B;AAAnB,0FAAA,GAAG,OAAA"}
|
|
@@ -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,iCAA8C;AAC9C,MAAM,MAAM,GAAG,IAAA,gBAAO,EAAC,SAAS,CAAC,CAAC;AAElC,MAAM,8BAA8B,GACnC,MAAM,CAAC,WAAW,CACjB,CAAC,YAAY,EAAE,YAAY,EAAE,YAAY,EAAE,YAAY,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC;IACrE,MAAM,CAAC,OAAO,CAAC,aAAa,GAAG,EAAE,CAAC;IAClC,IAAI;CACJ,CAAC,CACF,CAAC;AAEH,MAAa,KAAM,SAAQ,WAAY;IAAvC;;QACS,2BAAsB,GAAG,8BAA8B,CAAC;IA2BjE,CAAC;IAzBA,WAAW;QACV,OAAO,OAAO,CAAC;IAChB,CAAC;IAED,gBAAgB,CAAC,KAAe;QAC/B,IAAI,CAAC,sBAAsB,GAAG,MAAM,CAAC,WAAW,CAC/C,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CACjC,CAAC;QACF,OAAO,IAAI,CAAC;IACb,CAAC;IAEK,eAAe,CAAC,OAAmB;;YACxC,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAAC;YACtD,MAAM,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;YAC1D,IAAI,CAAC,IAAI,CAAC,sBAAsB,CAAC,GAAG,CAAC,EAAE;gBACtC,IAAI,CAAC,sBAAsB,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,WAAW,CACrD;oBACC,IAAI,EAAE,MAAM;oBACZ,IAAI,EAAE,GAAG;iBACT,EACD,IAAI,CACJ,CAAC;aACF;YACD,OAAO,IAAI,CAAC,sBAAsB,CAAC,GAAG,CAAoB,CAAC;QAC5D,CAAC;KAAA;CACD;AA5BD,sBA4BC"}
|
|
@@ -13,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,YACQ,SAA+B,EAC/B,gBAA+B,IAAI;QAE1C,KAAK,EAAE,CAAC;QAHD,cAAS,GAAT,SAAS,CAAsB;QAC/B,kBAAa,GAAb,aAAa,CAAsB;QAG1C,SAAS,CAAC,eAAe,GAAG,IAAI,CAAC;IAClC,CAAC;IAED,WAAW;QACV,OAAO,MAAM,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K,CAAC,KAAK,QAAQ,0BAA0B,CAAC,CAAC;aACzD;YACD,MAAM,MAAM,GAAG,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YACnE,IAAI,YAAY,GAA0B,MAAM,OAAO,CAAC,GAAG,CAC1D,MAAM,CAAC,GAAG,CAAC,CAAO,KAAK,EAAE,KAAK,EAAE,EAAE;gBACjC,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,cAAc,CACjD,OAAO,EACP,KAAK,EACL,GAAG,QAAQ,IAAI,KAAK,GAAG,CACvB,CAAC;gBACF,OAAO,MAAM,CAAC;YACf,CAAC,CAAA,CAAC,CACF,CAAC;YACF,IAAI,IAAI,CAAC,SAAS,CAAC,WAAW,EAAE,IAAI,MAAM,EAAE;gBAC3C,YAAY,GAAG,YAAY,CAAC,IAAI,EAAS,CAAC;aAC1C;YACD,OAAO,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,IAAI,CAAQ,CAAC;QACtD,CAAC;KAAA;CACD;AAxED,oBAwEC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.URL = void 0;
|
|
4
|
+
const component_argument_1 = require("./component-argument");
|
|
5
|
+
const ts_predicates_1 = require("@sealcode/ts-predicates");
|
|
6
|
+
class URL extends component_argument_1.ComponentArgument {
|
|
7
|
+
constructor(urlType) {
|
|
8
|
+
super();
|
|
9
|
+
this.urlType = urlType;
|
|
10
|
+
}
|
|
11
|
+
getTypeName() {
|
|
12
|
+
return `url`;
|
|
13
|
+
}
|
|
14
|
+
getEmptyValue() {
|
|
15
|
+
return "";
|
|
16
|
+
}
|
|
17
|
+
getExampleValue() {
|
|
18
|
+
if (this.urlType === "relative") {
|
|
19
|
+
return "/example";
|
|
20
|
+
}
|
|
21
|
+
return "https://example.com";
|
|
22
|
+
}
|
|
23
|
+
countWords() {
|
|
24
|
+
return 0;
|
|
25
|
+
}
|
|
26
|
+
parseFormInput(_, input) {
|
|
27
|
+
if ((0, ts_predicates_1.is)(input, ts_predicates_1.predicates.string)) {
|
|
28
|
+
return input;
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
exports.URL = URL;
|
|
36
|
+
//# sourceMappingURL=url.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"url.js","sourceRoot":"","sources":["../../src/component-arguments/url.ts"],"names":[],"mappings":";;;AACA,6DAAyD;AACzD,2DAAyD;AAGzD,MAAa,GAAI,SAAQ,sCAAyB;IAEjD,YAAY,OAA0C;QACrD,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACxB,CAAC;IAED,WAAW;QACV,OAAO,KAAK,CAAC;IACd,CAAC;IAED,aAAa;QACZ,OAAO,EAAE,CAAC;IACX,CAAC;IAED,eAAe;QACd,IAAI,IAAI,CAAC,OAAO,KAAK,UAAU,EAAE;YAChC,OAAO,UAAU,CAAC;SAClB;QAED,OAAO,qBAAqB,CAAC;IAC9B,CAAC;IAED,UAAU;QACT,OAAO,CAAC,CAAC;IACV,CAAC;IAED,cAAc,CACb,CAAa,EACb,KAAc;QAEd,IAAI,IAAA,kBAAE,EAAC,KAAK,EAAE,0BAAU,CAAC,MAAM,CAAC,EAAE;YACjC,OAAO,KAAK,CAAC;SACb;aAAM;YACN,OAAO,IAAI,CAAC;SACZ;IACF,CAAC;CACD;AArCD,kBAqCC"}
|