@sealcode/jdd 0.8.1 → 0.8.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/code.d.ts +14 -0
- package/@types/component-arguments/collection-name.d.ts +4 -0
- package/@types/component-arguments/component-arguments.d.ts +2 -0
- package/@types/component-arguments/enum.d.ts +5 -5
- package/lib/component-arguments/code.js +43 -0
- package/lib/component-arguments/code.js.map +1 -0
- package/lib/component-arguments/collection-name.js +7 -0
- package/lib/component-arguments/collection-name.js.map +1 -0
- package/lib/component-arguments/component-arguments.js +2 -0
- package/lib/component-arguments/component-arguments.js.map +1 -1
- package/lib/component-arguments/enum.js +8 -8
- package/lib/component-arguments/enum.js.map +1 -1
- package/lib/component-arguments/enum.test.js +1 -1
- package/lib/component-arguments/enum.test.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { MaybePromise } from "tempstream";
|
|
2
|
+
import { JDDContext } from "../jdd-context.js";
|
|
3
|
+
import { StringBasedArgument } from "./string-based-argument.js";
|
|
4
|
+
export declare class Code extends StringBasedArgument<string> {
|
|
5
|
+
readonly language: string;
|
|
6
|
+
constructor({ language }: {
|
|
7
|
+
language: string;
|
|
8
|
+
});
|
|
9
|
+
getTypeName(): string;
|
|
10
|
+
getEmptyValue(): string;
|
|
11
|
+
getExampleValue(): string;
|
|
12
|
+
countWords(_: JDDContext, value: string): number;
|
|
13
|
+
parseFormInput(_: JDDContext, input: unknown): MaybePromise<string | null>;
|
|
14
|
+
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { JDDContext } from "../jdd-context.js";
|
|
2
2
|
import { StringBasedArgument } from "./string-based-argument.js";
|
|
3
3
|
export declare class Enum<T extends string> extends StringBasedArgument<T> {
|
|
4
|
-
readonly
|
|
5
|
-
constructor(values: Readonly<T[]>);
|
|
4
|
+
readonly getValues: (context: JDDContext) => Readonly<T[]>;
|
|
5
|
+
constructor(values: Readonly<T[]> | ((context: JDDContext) => Readonly<T[]>));
|
|
6
6
|
getTypeName(): string;
|
|
7
|
-
getEmptyValue(): T;
|
|
8
|
-
getExampleValue(): T;
|
|
7
|
+
getEmptyValue(jdd_context: JDDContext): T;
|
|
8
|
+
getExampleValue(jdd_context: JDDContext): T;
|
|
9
9
|
countWords(): number;
|
|
10
|
-
parseFormInput(
|
|
10
|
+
parseFormInput(jdd_context: JDDContext, input: Record<string, unknown>): T | null;
|
|
11
11
|
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { is, predicates } from "@sealcode/ts-predicates";
|
|
2
|
+
import { StringBasedArgument } from "./string-based-argument.js";
|
|
3
|
+
export class Code extends StringBasedArgument {
|
|
4
|
+
constructor({ language }) {
|
|
5
|
+
super();
|
|
6
|
+
this.language = language;
|
|
7
|
+
}
|
|
8
|
+
getTypeName() {
|
|
9
|
+
return "code";
|
|
10
|
+
}
|
|
11
|
+
getEmptyValue() {
|
|
12
|
+
return "";
|
|
13
|
+
}
|
|
14
|
+
getExampleValue() {
|
|
15
|
+
return `
|
|
16
|
+
let maxSum = 0;
|
|
17
|
+
let tempSum = 0;
|
|
18
|
+
|
|
19
|
+
for (let i = 0; i < num; i++) {
|
|
20
|
+
maxSum += arr[i];
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
tempSum = maxSum;
|
|
24
|
+
|
|
25
|
+
for (let i = num; i < arr.length; i++) {
|
|
26
|
+
tempSum = tempSum - arr[i - num] + arr[i];
|
|
27
|
+
maxSum = Math.max(maxSum, tempSum);
|
|
28
|
+
}
|
|
29
|
+
`;
|
|
30
|
+
}
|
|
31
|
+
countWords(_, value) {
|
|
32
|
+
return value.toString().split(" ").length;
|
|
33
|
+
}
|
|
34
|
+
parseFormInput(_, input) {
|
|
35
|
+
if (is(input, predicates.string)) {
|
|
36
|
+
return input;
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=code.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"code.js","sourceRoot":"","sources":["../../src/component-arguments/code.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,EAAE,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAEzD,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAEjE,MAAM,OAAO,IAAK,SAAQ,mBAA2B;IAGpD,YAAY,EAAE,QAAQ,EAAwB;QAC7C,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC1B,CAAC;IAED,WAAW;QACV,OAAO,MAAM,CAAC;IACf,CAAC;IAED,aAAa;QACZ,OAAO,EAAE,CAAC;IACX,CAAC;IAED,eAAe;QACd,OAAO;;;;;;;;;;;;;;CAcR,CAAC;IACD,CAAC;IAED,UAAU,CAAC,CAAa,EAAE,KAAa;QACtC,OAAO,KAAK,CAAC,QAAQ,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC;IAC3C,CAAC;IAED,cAAc,CAAC,CAAa,EAAE,KAAc;QAC3C,IAAI,EAAE,CAAC,KAAK,EAAE,UAAU,CAAC,MAAM,CAAC,EAAE;YACjC,OAAO,KAAK,CAAC;SACb;aAAM;YACN,OAAO,IAAI,CAAC;SACZ;IACF,CAAC;CACD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"collection-name.js","sourceRoot":"","sources":["../../src/component-arguments/collection-name.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,MAAM,OAAO,cAAe,SAAQ,IAAY;IAC/C;QACC,KAAK,CAAC,CAAC,WAAuB,EAAE,EAAE,CACjC,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,WAAW,CAAC,CACrD,CAAC;IACH,CAAC;CACD"}
|
|
@@ -12,4 +12,6 @@ export { URL } from "./url.js";
|
|
|
12
12
|
export { Number } from "./number.js";
|
|
13
13
|
export { Color } from "./color.js";
|
|
14
14
|
export { Link } from "./link.js";
|
|
15
|
+
export { Code } from "./code.js";
|
|
16
|
+
export { CollectionName } from "./collection-name.js";
|
|
15
17
|
//# 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,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,gBAAgB,IAAI,QAAQ,EAAE,MAAM,eAAe,CAAC;AAC7D,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,cAAc,uBAAuB,CAAC;AACtC,cAAc,YAAY,CAAC;AAC3B,cAAc,uBAAuB,CAAC;AACtC,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAC/B,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC"}
|
|
1
|
+
{"version":3,"file":"component-arguments.js","sourceRoot":"","sources":["../../src/component-arguments/component-arguments.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,gBAAgB,IAAI,QAAQ,EAAE,MAAM,eAAe,CAAC;AAC7D,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,cAAc,uBAAuB,CAAC;AACtC,cAAc,YAAY,CAAC;AAC3B,cAAc,uBAAuB,CAAC;AACtC,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAC/B,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC"}
|
|
@@ -3,28 +3,28 @@ import { StringBasedArgument } from "./string-based-argument.js";
|
|
|
3
3
|
export class Enum extends StringBasedArgument {
|
|
4
4
|
constructor(values) {
|
|
5
5
|
super();
|
|
6
|
-
this.
|
|
6
|
+
this.getValues = typeof values == "function" ? values : () => values;
|
|
7
7
|
}
|
|
8
8
|
getTypeName() {
|
|
9
9
|
return "enum";
|
|
10
10
|
}
|
|
11
|
-
getEmptyValue() {
|
|
12
|
-
return this.
|
|
11
|
+
getEmptyValue(jdd_context) {
|
|
12
|
+
return this.getValues(jdd_context)[0];
|
|
13
13
|
}
|
|
14
|
-
getExampleValue() {
|
|
14
|
+
getExampleValue(jdd_context) {
|
|
15
15
|
const pick_from = this.example_values.length
|
|
16
16
|
? this.example_values
|
|
17
|
-
: this.
|
|
17
|
+
: this.getValues(jdd_context);
|
|
18
18
|
return pick_from[Math.floor(Math.random() * pick_from.length)];
|
|
19
19
|
}
|
|
20
20
|
countWords() {
|
|
21
21
|
return 0;
|
|
22
22
|
}
|
|
23
23
|
// TODO: this should be maybe removed or change into receivedToParsed?
|
|
24
|
-
parseFormInput(
|
|
24
|
+
parseFormInput(jdd_context, input) {
|
|
25
25
|
if (is(input, predicates.string) &&
|
|
26
|
-
(is(input, predicates.enum(this.
|
|
27
|
-
is(input.trim(), predicates.enum(this.
|
|
26
|
+
(is(input, predicates.enum(this.getValues(jdd_context))) ||
|
|
27
|
+
is(input.trim(), predicates.enum(this.getValues(jdd_context))))) {
|
|
28
28
|
return input.trim();
|
|
29
29
|
}
|
|
30
30
|
else {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"enum.js","sourceRoot":"","sources":["../../src/component-arguments/enum.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAEzD,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAEjE,MAAM,OAAO,IAAuB,SAAQ,mBAAsB;IAEjE,
|
|
1
|
+
{"version":3,"file":"enum.js","sourceRoot":"","sources":["../../src/component-arguments/enum.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAEzD,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAEjE,MAAM,OAAO,IAAuB,SAAQ,mBAAsB;IAEjE,YACC,MAAgE;QAEhE,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,SAAS,GAAG,OAAO,MAAM,IAAI,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC;IACtE,CAAC;IAED,WAAW;QACV,OAAO,MAAM,CAAC;IACf,CAAC;IAED,aAAa,CAAC,WAAuB;QACpC,OAAO,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;IACvC,CAAC;IAED,eAAe,CAAC,WAAuB;QACtC,MAAM,SAAS,GAAG,IAAI,CAAC,cAAc,CAAC,MAAM;YAC3C,CAAC,CAAC,IAAI,CAAC,cAAc;YACrB,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;QAC/B,OAAO,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC;IAChE,CAAC;IAED,UAAU;QACT,OAAO,CAAC,CAAC;IACV,CAAC;IAED,sEAAsE;IACtE,cAAc,CAAC,WAAuB,EAAE,KAA8B;QACrE,IACC,EAAE,CAAC,KAAK,EAAE,UAAU,CAAC,MAAM,CAAC;YAC5B,CAAC,EAAE,CAAC,KAAK,EAAE,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC,CAAC;gBACvD,EAAE,CAAC,KAAK,CAAC,IAAI,EAAE,EAAE,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,EAC/D;YACD,OAAO,KAAK,CAAC,IAAI,EAAO,CAAC;SACzB;aAAM;YACN,OAAO,IAAI,CAAC;SACZ;IACF,CAAC;CACD"}
|
|
@@ -4,7 +4,7 @@ describe("enum argument", () => {
|
|
|
4
4
|
it("uses only the example values if provided when running getExampleValues", () => {
|
|
5
5
|
const e = new Enum(["a", "b"]).setExampleValues(["a"]);
|
|
6
6
|
for (let i = 0; i <= 100; i++) {
|
|
7
|
-
assert.deepStrictEqual(e.getExampleValue(), "a");
|
|
7
|
+
assert.deepStrictEqual(e.getExampleValue({}), "a");
|
|
8
8
|
}
|
|
9
9
|
});
|
|
10
10
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"enum.test.js","sourceRoot":"","sources":["../../src/component-arguments/enum.test.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,QAAQ,CAAC,eAAe,EAAE,GAAG,EAAE;IAC9B,EAAE,CAAC,wEAAwE,EAAE,GAAG,EAAE;QACjF,MAAM,CAAC,GAAG,IAAI,IAAI,CAAC,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;QACvD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,GAAG,EAAE,CAAC,EAAE,EAAE;YAC9B,MAAM,CAAC,eAAe,CAAC,CAAC,CAAC,eAAe,
|
|
1
|
+
{"version":3,"file":"enum.test.js","sourceRoot":"","sources":["../../src/component-arguments/enum.test.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,QAAQ,CAAC,eAAe,EAAE,GAAG,EAAE;IAC9B,EAAE,CAAC,wEAAwE,EAAE,GAAG,EAAE;QACjF,MAAM,CAAC,GAAG,IAAI,IAAI,CAAC,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;QACvD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,GAAG,EAAE,CAAC,EAAE,EAAE;YAC9B,MAAM,CAAC,eAAe,CAAC,CAAC,CAAC,eAAe,CAAC,EAAS,CAAC,EAAE,GAAG,CAAC,CAAC;SAC1D;IACF,CAAC,CAAC,CAAC;AACJ,CAAC,CAAC,CAAC"}
|