@sealcode/jdd 0.2.18 → 0.3.1

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.
Files changed (61) hide show
  1. package/@types/component-arguments/component-argument.d.ts +17 -0
  2. package/@types/component-arguments/component-arguments.d.ts +8 -0
  3. package/@types/component-arguments/enum.d.ts +11 -0
  4. package/@types/component-arguments/file.d.ts +11 -0
  5. package/@types/component-arguments/image.d.ts +6 -0
  6. package/@types/component-arguments/list.d.ts +11 -0
  7. package/@types/component-arguments/markdown.d.ts +10 -0
  8. package/@types/component-arguments/short-text.d.ts +10 -0
  9. package/@types/component-arguments/structured.d.ts +17 -0
  10. package/@types/component-arguments/table.d.ts +39 -0
  11. package/@types/component-arguments.d.ts +9 -1
  12. package/@types/component.d.ts +3 -3
  13. package/@types/components/markdown.d.ts +2 -1
  14. package/@types/index.d.ts +7 -7
  15. package/@types/jdd-context.d.ts +24 -0
  16. package/@types/utils/fix-array.d.ts +3 -0
  17. package/@types/utils/maybepromise.d.ts +1 -0
  18. package/@types/utils/util-types.d.ts +1 -0
  19. package/lib/component-arguments/component-argument.js +28 -0
  20. package/lib/component-arguments/component-argument.js.map +1 -0
  21. package/lib/component-arguments/component-arguments.js +33 -0
  22. package/lib/component-arguments/component-arguments.js.map +1 -0
  23. package/lib/component-arguments/enum.js +35 -0
  24. package/lib/component-arguments/enum.js.map +1 -0
  25. package/lib/component-arguments/file.js +79 -0
  26. package/lib/component-arguments/file.js.map +1 -0
  27. package/lib/component-arguments/image.js +44 -0
  28. package/lib/component-arguments/image.js.map +1 -0
  29. package/lib/component-arguments/list.js +67 -0
  30. package/lib/component-arguments/list.js.map +1 -0
  31. package/lib/component-arguments/markdown.js +39 -0
  32. package/lib/component-arguments/markdown.js.map +1 -0
  33. package/lib/component-arguments/short-text.js +35 -0
  34. package/lib/component-arguments/short-text.js.map +1 -0
  35. package/lib/component-arguments/structured.js +95 -0
  36. package/lib/component-arguments/structured.js.map +1 -0
  37. package/lib/component-arguments/table.js +150 -0
  38. package/lib/component-arguments/table.js.map +1 -0
  39. package/lib/component-arguments.js +26 -11
  40. package/lib/component-arguments.js.map +1 -1
  41. package/lib/component.js +28 -5
  42. package/lib/component.js.map +1 -1
  43. package/lib/components/markdown.js +4 -3
  44. package/lib/components/markdown.js.map +1 -1
  45. package/lib/index.js +30 -7
  46. package/lib/index.js.map +1 -1
  47. package/lib/jdd-context.js +73 -0
  48. package/lib/jdd-context.js.map +1 -0
  49. package/lib/utils/fix-array.js +16 -0
  50. package/lib/utils/fix-array.js.map +1 -0
  51. package/lib/utils/insert_nbsp.js +1 -1
  52. package/lib/utils/insert_nbsp.js.map +1 -1
  53. package/lib/utils/maybepromise.js +3 -0
  54. package/lib/utils/maybepromise.js.map +1 -0
  55. package/lib/utils/util-types.js +3 -0
  56. package/lib/utils/util-types.js.map +1 -0
  57. package/package.json +8 -2
  58. package/resources/image1.jpg +0 -0
  59. package/resources/image3.jpg +0 -0
  60. package/resources/image4.jpg +0 -0
  61. package/resources/image5.jpg +0 -0
@@ -0,0 +1,17 @@
1
+ import { JDDContext, List } from "../index";
2
+ import { MaybePromise } from "../utils/util-types";
3
+ export type ExtractComponentArgumentValue<C> = C extends List<infer S> ? S[] : C extends ComponentArgument<infer T> ? T : never;
4
+ export type ExtractStructuredComponentArgumentsValues<C> = {
5
+ [property in keyof C]: ExtractComponentArgumentValue<C[property]>;
6
+ };
7
+ export declare abstract class ComponentArgument<ARG> {
8
+ example_values: ARG[];
9
+ parent_argument: ComponentArgument<unknown> | null;
10
+ abstract getTypeName(): string;
11
+ abstract getEmptyValue(): ARG;
12
+ abstract countWords(value: ARG): number;
13
+ abstract parseFormInput(context: JDDContext, input: unknown, arg_name: string): MaybePromise<ARG | ARG[] | null>;
14
+ getExampleValue(_context: JDDContext): Promise<ARG> | ARG;
15
+ setExampleValues(values: ARG[]): this;
16
+ hasParent(type: string): boolean;
17
+ }
@@ -0,0 +1,8 @@
1
+ export { Enum } from "./enum";
2
+ export { Image } from "./image";
3
+ export { File } from "./file";
4
+ export { List } from "./list";
5
+ export { MarkdownArgument as Markdown } from "./markdown";
6
+ export { ShortText } from "./short-text";
7
+ export { Structured } from "./structured";
8
+ export * from "./table";
@@ -0,0 +1,11 @@
1
+ import { ComponentArgument } from "./component-argument";
2
+ import { JDDContext } from "../jdd-context";
3
+ export declare class Enum<T extends string> extends ComponentArgument<T> {
4
+ readonly values: Readonly<T[]>;
5
+ constructor(values: Readonly<T[]>);
6
+ getTypeName(): string;
7
+ getEmptyValue(): T;
8
+ getExampleValue(): T;
9
+ countWords(): number;
10
+ parseFormInput(_: JDDContext, input: Record<string, unknown>): T | null;
11
+ }
@@ -0,0 +1,11 @@
1
+ import { JDDContext } from "../index";
2
+ import { ComponentArgument } from "./component-argument";
3
+ export declare function encodeSealiousFile(context: JDDContext, maybe_file: Record<string, unknown>): Promise<string | null>;
4
+ export declare class File extends ComponentArgument<string | null> {
5
+ constructor();
6
+ getTypeName(): string;
7
+ getEmptyValue(): null;
8
+ getExampleValue(_context: JDDContext): Promise<string>;
9
+ countWords(): number;
10
+ parseFormInput(context: JDDContext, input: unknown): Promise<string | string[] | null>;
11
+ }
@@ -0,0 +1,6 @@
1
+ import { JDDContext } from "..";
2
+ import { File as FileArgument } from "./file";
3
+ export declare class Image extends FileArgument {
4
+ getTypeName(): string;
5
+ getExampleValue(context: JDDContext): Promise<string>;
6
+ }
@@ -0,0 +1,11 @@
1
+ import { JDDContext } from "..";
2
+ import { ComponentArgument } from "./component-argument";
3
+ export declare class List<T> extends ComponentArgument<Array<T>> {
4
+ item_type: ComponentArgument<T>;
5
+ constructor(item_type: ComponentArgument<T>);
6
+ getTypeName(): string;
7
+ getEmptyValue(): never[];
8
+ getExampleValue(context: JDDContext): Promise<T[]>;
9
+ countWords(value: Array<T>): number;
10
+ parseFormInput(context: JDDContext, input: unknown, arg_name: string): Promise<T[] | null>;
11
+ }
@@ -0,0 +1,10 @@
1
+ import { JDDContext } from "../jdd-context";
2
+ import { MaybePromise } from "../utils/util-types";
3
+ import { ComponentArgument } from "./component-argument";
4
+ export declare class MarkdownArgument extends ComponentArgument<string> {
5
+ getTypeName(): string;
6
+ getEmptyValue(): string;
7
+ countWords(value: string): number;
8
+ example_values: string[];
9
+ parseFormInput(_: JDDContext, input: unknown): MaybePromise<string | string[] | null>;
10
+ }
@@ -0,0 +1,10 @@
1
+ import { JDDContext } from "..";
2
+ import { MaybePromise } from "../utils/util-types";
3
+ import { ComponentArgument } from "./component-argument";
4
+ export declare class ShortText extends ComponentArgument<string> {
5
+ example_values: string[];
6
+ getTypeName(): string;
7
+ getEmptyValue(): string;
8
+ countWords(value: string): number;
9
+ parseFormInput(_: JDDContext, input: unknown): MaybePromise<string | string[] | null>;
10
+ }
@@ -0,0 +1,17 @@
1
+ import { JDDContext } from "..";
2
+ import { ComponentArgument, ExtractComponentArgumentValue } from "./component-argument";
3
+ export declare class Structured<T extends Record<string, ComponentArgument<unknown>>> extends ComponentArgument<{
4
+ [property in keyof T]: ExtractComponentArgumentValue<T[property]>;
5
+ }> {
6
+ structure: T;
7
+ constructor(structure: T);
8
+ getTypeName(): string;
9
+ countWords(value: {
10
+ [property in keyof T]: ExtractComponentArgumentValue<T[property]>;
11
+ }): number;
12
+ getEmptyValue(): { [property in keyof T]: ExtractComponentArgumentValue<T[property]>; };
13
+ getExampleValue(context: JDDContext): Promise<{ [property in keyof T]: ExtractComponentArgumentValue<T[property]>; }>;
14
+ parseFormInput<SingleObject extends {
15
+ [property in keyof T]: ExtractComponentArgumentValue<T[property]>;
16
+ }>(context: JDDContext, input: unknown, arg_name: string): Promise<SingleObject | SingleObject[] | null>;
17
+ }
@@ -0,0 +1,39 @@
1
+ import { JDDContext } from "..";
2
+ import { ComponentArgument } from "./component-argument";
3
+ type TableHeader<HeaderType> = {
4
+ type: "header";
5
+ header_content: HeaderType;
6
+ };
7
+ type TableRegularRow<CellType> = {
8
+ type: "row";
9
+ cells: CellType[];
10
+ };
11
+ export type TableRow<CellType, HeaderType> = TableHeader<HeaderType> | TableRegularRow<CellType>;
12
+ export type TableData<CellType, HeaderType> = {
13
+ rows: TableRow<CellType, HeaderType>[];
14
+ };
15
+ export declare function isTableHeader(x: unknown): x is TableHeader<unknown>;
16
+ export declare function isTableRegularRow<CellType = unknown>(x: unknown): x is TableRegularRow<CellType>;
17
+ export declare function isTableData<CellType = unknown, HeaderType = unknown>(x: unknown): x is TableData<CellType, HeaderType>;
18
+ export declare class Table<CellType, HeaderType> extends ComponentArgument<TableData<CellType, HeaderType>> {
19
+ header_type: ComponentArgument<HeaderType>;
20
+ cell_type: ComponentArgument<CellType>;
21
+ constructor(header_type: ComponentArgument<HeaderType>, cell_type: ComponentArgument<CellType>);
22
+ getTypeName(): string;
23
+ getEmptyValue(): {
24
+ rows: ({
25
+ type: "header";
26
+ header_content: HeaderType;
27
+ cells?: undefined;
28
+ } | {
29
+ type: "row";
30
+ cells: CellType[];
31
+ header_content?: undefined;
32
+ })[];
33
+ };
34
+ getExampleValue(context: JDDContext): Promise<TableData<CellType, HeaderType>>;
35
+ countWords(value: TableData<CellType, HeaderType>): number;
36
+ parseFormInput(context: JDDContext, input: unknown, arg_name: string): Promise<TableData<CellType, HeaderType> | TableData<CellType, HeaderType>[] | null>;
37
+ getColumnsCount(value: TableData<CellType, HeaderType>): number;
38
+ }
39
+ export {};
@@ -3,7 +3,7 @@ export type ExtractStructuredComponentArgumentsValues<C> = {
3
3
  [property in keyof C]: ExtractComponentArgumentValue<C[property]>;
4
4
  };
5
5
  export type T = ExtractComponentArgumentValue<Structured<any>>;
6
- export declare abstract class ComponentArgument<ARG extends any> {
6
+ export declare abstract class ComponentArgument<ARG> {
7
7
  example_values: ARG[];
8
8
  abstract getTypeName(): string;
9
9
  abstract getEmptyValue(): ARG;
@@ -50,6 +50,13 @@ export declare class Image extends ComponentArgument<string> {
50
50
  getEmptyValue(): string;
51
51
  getExampleValue(): string;
52
52
  }
53
+ export declare class URL extends ComponentArgument<string> {
54
+ readonly urlType: Readonly<"relative" | "absolute">;
55
+ constructor(urlType: Readonly<"relative" | "absolute">);
56
+ getTypeName(): string;
57
+ getEmptyValue(): string;
58
+ getExampleValue(): "/example" | "https://example.com";
59
+ }
53
60
  export declare const ComponentArguments: {
54
61
  Image: typeof Image;
55
62
  Structured: typeof Structured;
@@ -57,4 +64,5 @@ export declare const ComponentArguments: {
57
64
  Markdown: typeof MarkdownArgument;
58
65
  ShortText: typeof ShortText;
59
66
  Enum: typeof Enum;
67
+ URL: typeof URL;
60
68
  };
@@ -1,11 +1,11 @@
1
1
  import { FlatTemplatable } from "tempstream";
2
- import { ComponentArgument, ExtractStructuredComponentArgumentsValues } from "./component-arguments";
3
- import { JDDContext } from ".";
2
+ import { ComponentArgument, ExtractStructuredComponentArgumentsValues, JDDContext } from ".";
4
3
  export interface ComponentConstructor<A extends Record<string, ComponentArgument<unknown>> = Record<string, ComponentArgument<unknown>>> {
5
4
  new (): Component<A>;
6
5
  }
7
6
  export declare abstract class Component<ArgumentsT extends Record<string, ComponentArgument<unknown>> = Record<string, ComponentArgument<unknown>>> {
8
7
  abstract getArguments(): ArgumentsT;
9
8
  abstract toHTML(args: ExtractStructuredComponentArgumentsValues<ArgumentsT>, context: JDDContext): FlatTemplatable;
10
- getExampleValues(): ExtractStructuredComponentArgumentsValues<ArgumentsT>;
9
+ countWords(args: Record<string, unknown>): number;
10
+ getExampleValues(context: JDDContext): Promise<ExtractStructuredComponentArgumentsValues<ArgumentsT>>;
11
11
  }
@@ -1,6 +1,7 @@
1
1
  import { FlatTemplatable } from "tempstream";
2
2
  import { Component } from "../component";
3
- import { ExtractStructuredComponentArgumentsValues, MarkdownArgument } from "../component-arguments";
3
+ import { MarkdownArgument } from "../component-arguments/markdown";
4
+ import { ExtractStructuredComponentArgumentsValues } from "../component-arguments/component-argument";
4
5
  declare const component_arguments: {
5
6
  readonly markdown: MarkdownArgument;
6
7
  };
package/@types/index.d.ts CHANGED
@@ -1,16 +1,16 @@
1
1
  /// <reference types="node" />
2
- import { FlatTemplatable } from "tempstream";
2
+ import { JDDContext } from "./jdd-context";
3
3
  import { Registry } from "./registry";
4
- export * from "./component-arguments";
5
4
  export * from "./component";
5
+ export * from "./component-arguments/component-argument";
6
+ export * as ComponentArguments from "./component-arguments/component-arguments";
7
+ export * from "./component-arguments/component-arguments";
8
+ export * from "./jdd-context";
6
9
  export * from "./registry";
10
+ export { insert_nbsp } from "./utils/insert_nbsp";
7
11
  export type JDDocument = Array<{
8
12
  component_name: string;
9
13
  args: Record<string, unknown>;
10
14
  }>;
11
- export interface JDDContext {
12
- render_image: (path_to_image: string) => FlatTemplatable;
13
- render_markdown: (markdown: string) => FlatTemplatable;
14
- }
15
- export declare const simpleJDDContext: JDDContext;
15
+ export declare function countWords(registry: Registry, document: JDDocument): number;
16
16
  export declare function render(registry: Registry, document: JDDocument, context: JDDContext): import("stream").Readable;
@@ -0,0 +1,24 @@
1
+ /// <reference types="node" />
2
+ import type { KoaResponsiveImageRouter } from "koa-responsive-image-router";
3
+ import { FlatTemplatable } from "tempstream";
4
+ export type FSFilePointer = {
5
+ type: "path";
6
+ path: string;
7
+ mimetype?: string;
8
+ };
9
+ export type FilePointer = FSFilePointer | {
10
+ type: "buffer";
11
+ mimetype: string;
12
+ buffer: Buffer;
13
+ };
14
+ export interface JDDContext {
15
+ render_image: (file_id: string | null, args: Parameters<KoaResponsiveImageRouter["image"]>[1]) => FlatTemplatable;
16
+ render_markdown: (markdown: string) => FlatTemplatable;
17
+ encode_file: (photo: FilePointer, persistent: boolean) => Promise<string>;
18
+ decode_file: (id: string) => Promise<FSFilePointer | null>;
19
+ }
20
+ export declare function makeSimplePhotoStorage(persistent_dir_path: string): {
21
+ decode_file: (id: string) => Promise<FSFilePointer | null>;
22
+ encode_file: (file_pointer: FilePointer, persistent: boolean) => Promise<string>;
23
+ };
24
+ export declare const simpleJDDContext: JDDContext;
@@ -0,0 +1,3 @@
1
+ export declare function fixArrays<Keys extends string, T extends Record<string, unknown>, Result extends {
2
+ [K in Keys]: T[K] extends Record<string, infer E> ? E[] : never;
3
+ }>(object: T, ...keys: Keys[]): Omit<T, Keys> & Result;
@@ -0,0 +1 @@
1
+ export type MaybePromise<T> = Promise<T> | T;
@@ -0,0 +1 @@
1
+ export type MaybePromise<T> = Promise<T> | T;
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ComponentArgument = void 0;
4
+ class ComponentArgument {
5
+ constructor() {
6
+ this.example_values = [];
7
+ this.parent_argument = null;
8
+ }
9
+ getExampleValue(_context) {
10
+ return this.example_values[Math.floor(this.example_values.length * Math.random())];
11
+ }
12
+ setExampleValues(values) {
13
+ this.example_values = values;
14
+ return this;
15
+ }
16
+ hasParent(type) {
17
+ let parent = this.parent_argument;
18
+ while (parent) {
19
+ if (parent.getTypeName() == type) {
20
+ return true;
21
+ }
22
+ parent = parent.parent_argument;
23
+ }
24
+ return false;
25
+ }
26
+ }
27
+ exports.ComponentArgument = ComponentArgument;
28
+ //# sourceMappingURL=component-argument.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"component-argument.js","sourceRoot":"","sources":["../../src/component-arguments/component-argument.ts"],"names":[],"mappings":";;;AAaA,MAAsB,iBAAiB;IAAvC;QACQ,mBAAc,GAAU,EAAE,CAAC;QAC3B,oBAAe,GAAsC,IAAI,CAAC;IA+BlE,CAAC;IArBA,eAAe,CAAC,QAAoB;QACnC,OAAO,IAAI,CAAC,cAAc,CACzB,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,cAAc,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,CACtD,CAAC;IACH,CAAC;IAED,gBAAgB,CAAC,MAAa;QAC7B,IAAI,CAAC,cAAc,GAAG,MAAM,CAAC;QAC7B,OAAO,IAAI,CAAC;IACb,CAAC;IAED,SAAS,CAAC,IAAY;QACrB,IAAI,MAAM,GAAG,IAAI,CAAC,eAAe,CAAC;QAClC,OAAO,MAAM,EAAE;YACd,IAAI,MAAM,CAAC,WAAW,EAAE,IAAI,IAAI,EAAE;gBACjC,OAAO,IAAI,CAAC;aACZ;YACD,MAAM,GAAG,MAAM,CAAC,eAAe,CAAC;SAChC;QACD,OAAO,KAAK,CAAC;IACd,CAAC;CACD;AAjCD,8CAiCC"}
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.Structured = exports.ShortText = exports.Markdown = exports.List = exports.File = exports.Image = exports.Enum = void 0;
18
+ var enum_1 = require("./enum");
19
+ Object.defineProperty(exports, "Enum", { enumerable: true, get: function () { return enum_1.Enum; } });
20
+ var image_1 = require("./image");
21
+ Object.defineProperty(exports, "Image", { enumerable: true, get: function () { return image_1.Image; } });
22
+ var file_1 = require("./file");
23
+ Object.defineProperty(exports, "File", { enumerable: true, get: function () { return file_1.File; } });
24
+ var list_1 = require("./list");
25
+ Object.defineProperty(exports, "List", { enumerable: true, get: function () { return list_1.List; } });
26
+ var markdown_1 = require("./markdown");
27
+ Object.defineProperty(exports, "Markdown", { enumerable: true, get: function () { return markdown_1.MarkdownArgument; } });
28
+ var short_text_1 = require("./short-text");
29
+ Object.defineProperty(exports, "ShortText", { enumerable: true, get: function () { return short_text_1.ShortText; } });
30
+ var structured_1 = require("./structured");
31
+ Object.defineProperty(exports, "Structured", { enumerable: true, get: function () { return structured_1.Structured; } });
32
+ __exportStar(require("./table"), exports);
33
+ //# sourceMappingURL=component-arguments.js.map
@@ -0,0 +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"}
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Enum = void 0;
4
+ const ts_predicates_1 = require("@sealcode/ts-predicates");
5
+ const component_argument_1 = require("./component-argument");
6
+ class Enum extends component_argument_1.ComponentArgument {
7
+ constructor(values) {
8
+ super();
9
+ this.values = values;
10
+ }
11
+ getTypeName() {
12
+ return "enum";
13
+ }
14
+ getEmptyValue() {
15
+ return this.values[0];
16
+ }
17
+ getExampleValue() {
18
+ return this.values[Math.floor(Math.random() * this.values.length)];
19
+ }
20
+ countWords() {
21
+ return 0;
22
+ }
23
+ parseFormInput(_, input) {
24
+ if ((0, ts_predicates_1.is)(input, ts_predicates_1.predicates.string) &&
25
+ ((0, ts_predicates_1.is)(input, ts_predicates_1.predicates.enum(this.values)) ||
26
+ (0, ts_predicates_1.is)(input.trim(), ts_predicates_1.predicates.enum(this.values)))) {
27
+ return input.trim();
28
+ }
29
+ else {
30
+ return null;
31
+ }
32
+ }
33
+ }
34
+ exports.Enum = Enum;
35
+ //# sourceMappingURL=enum.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"enum.js","sourceRoot":"","sources":["../../src/component-arguments/enum.ts"],"names":[],"mappings":";;;AAAA,2DAAyD;AACzD,6DAAyD;AAGzD,MAAa,IAAuB,SAAQ,sCAAoB;IAE/D,YAAY,MAAqB;QAChC,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACtB,CAAC;IAED,WAAW;QACV,OAAO,MAAM,CAAC;IACf,CAAC;IAED,aAAa;QACZ,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IACvB,CAAC;IAED,eAAe;QACd,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC;IACpE,CAAC;IAED,UAAU;QACT,OAAO,CAAC,CAAC;IACV,CAAC;IAED,cAAc,CAAC,CAAa,EAAE,KAA8B;QAC3D,IACC,IAAA,kBAAE,EAAC,KAAK,EAAE,0BAAU,CAAC,MAAM,CAAC;YAC5B,CAAC,IAAA,kBAAE,EAAC,KAAK,EAAE,0BAAU,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;gBACvC,IAAA,kBAAE,EAAC,KAAK,CAAC,IAAI,EAAE,EAAE,0BAAU,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,EAC/C;YACD,OAAO,KAAK,CAAC,IAAI,EAAO,CAAC;SACzB;aAAM;YACN,OAAO,IAAI,CAAC;SACZ;IACF,CAAC;CACD;AAlCD,oBAkCC"}
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.File = exports.encodeSealiousFile = void 0;
13
+ const ts_predicates_1 = require("@sealcode/ts-predicates");
14
+ const component_argument_1 = require("./component-argument");
15
+ function isSealiousFile(x) {
16
+ return (0, ts_predicates_1.hasShape)({
17
+ getDataPath: ts_predicates_1.predicates.any,
18
+ data: ts_predicates_1.predicates.shape({ path: ts_predicates_1.predicates.string }),
19
+ }, x);
20
+ }
21
+ function encodeSealiousFile(context, maybe_file) {
22
+ return __awaiter(this, void 0, void 0, function* () {
23
+ if (isSealiousFile(maybe_file)) {
24
+ return context.encode_file({
25
+ type: "path",
26
+ // asserting that this is an instance of sealious' FileFromPath
27
+ path: maybe_file.data.path,
28
+ }, false);
29
+ }
30
+ else {
31
+ return null;
32
+ }
33
+ });
34
+ }
35
+ exports.encodeSealiousFile = encodeSealiousFile;
36
+ class File extends component_argument_1.ComponentArgument {
37
+ constructor() {
38
+ super();
39
+ }
40
+ getTypeName() {
41
+ return "file";
42
+ }
43
+ getEmptyValue() {
44
+ return null;
45
+ }
46
+ getExampleValue(_context) {
47
+ return __awaiter(this, void 0, void 0, function* () {
48
+ return "";
49
+ });
50
+ }
51
+ countWords() {
52
+ return 0;
53
+ }
54
+ parseFormInput(context, input) {
55
+ return __awaiter(this, void 0, void 0, function* () {
56
+ if (!(0, ts_predicates_1.hasShape)({
57
+ new: ts_predicates_1.predicates.maybe(ts_predicates_1.predicates.array(ts_predicates_1.predicates.object)),
58
+ old: ts_predicates_1.predicates.string,
59
+ }, input)) {
60
+ return null;
61
+ }
62
+ const files = (input.new || []).filter((e) => e);
63
+ if (files.length == 0) {
64
+ return input.old;
65
+ }
66
+ else if (files.length == 1) {
67
+ return encodeSealiousFile(context, files[0]);
68
+ }
69
+ else if (this.hasParent("list")) {
70
+ return (yield Promise.all(files.map((file) => encodeSealiousFile(context, file)))).filter((e) => e !== null);
71
+ }
72
+ else {
73
+ return null;
74
+ }
75
+ });
76
+ }
77
+ }
78
+ exports.File = File;
79
+ //# sourceMappingURL=file.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file.js","sourceRoot":"","sources":["../../src/component-arguments/file.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2DAA+D;AAE/D,6DAAyD;AAEzD,SAAS,cAAc,CAAC,CAAU;IACjC,OAAO,IAAA,wBAAQ,EACd;QACC,WAAW,EAAE,0BAAU,CAAC,GAAG;QAC3B,IAAI,EAAE,0BAAU,CAAC,KAAK,CAAC,EAAE,IAAI,EAAE,0BAAU,CAAC,MAAM,EAAE,CAAC;KACnD,EACD,CAAC,CACD,CAAC;AACH,CAAC;AAED,SAAsB,kBAAkB,CACvC,OAAmB,EACnB,UAAmC;;QAEnC,IAAI,cAAc,CAAC,UAAU,CAAC,EAAE;YAC/B,OAAO,OAAO,CAAC,WAAW,CACzB;gBACC,IAAI,EAAE,MAAM;gBACZ,+DAA+D;gBAC/D,IAAI,EAAE,UAAU,CAAC,IAAI,CAAC,IAAI;aAC1B,EACD,KAAK,CACL,CAAC;SACF;aAAM;YACN,OAAO,IAAI,CAAC;SACZ;IACF,CAAC;CAAA;AAhBD,gDAgBC;AAED,MAAa,IAAK,SAAQ,sCAAgC;IACzD;QACC,KAAK,EAAE,CAAC;IACT,CAAC;IAED,WAAW;QACV,OAAO,MAAM,CAAC;IACf,CAAC;IAED,aAAa;QACZ,OAAO,IAAI,CAAC;IACb,CAAC;IAEK,eAAe,CAAC,QAAoB;;YACzC,OAAO,EAAE,CAAC;QACX,CAAC;KAAA;IAED,UAAU;QACT,OAAO,CAAC,CAAC;IACV,CAAC;IAEK,cAAc,CACnB,OAAmB,EACnB,KAAc;;YAEd,IACC,CAAC,IAAA,wBAAQ,EACR;gBACC,GAAG,EAAE,0BAAU,CAAC,KAAK,CAAC,0BAAU,CAAC,KAAK,CAAC,0BAAU,CAAC,MAAM,CAAC,CAAC;gBAC1D,GAAG,EAAE,0BAAU,CAAC,MAAM;aACtB,EACD,KAAK,CACL,EACA;gBACD,OAAO,IAAI,CAAC;aACZ;YACD,MAAM,KAAK,GAAG,CAAC,KAAK,CAAC,GAAG,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC;YACjD,IAAI,KAAK,CAAC,MAAM,IAAI,CAAC,EAAE;gBACtB,OAAO,KAAK,CAAC,GAAG,CAAC;aACjB;iBAAM,IAAI,KAAK,CAAC,MAAM,IAAI,CAAC,EAAE;gBAC7B,OAAO,kBAAkB,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;aAC7C;iBAAM,IAAI,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE;gBAClC,OAAO,CACN,MAAM,OAAO,CAAC,GAAG,CAChB,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,kBAAkB,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,CACtD,CACD,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,IAAI,CAAa,CAAC;aACxC;iBAAM;gBACN,OAAO,IAAI,CAAC;aACZ;QACF,CAAC;KAAA;CACD;AAnDD,oBAmDC"}
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.Image = void 0;
16
+ const locreq_1 = __importDefault(require("locreq"));
17
+ const file_1 = require("./file");
18
+ const locreq = (0, locreq_1.default)(__dirname);
19
+ let example_image_promises = {
20
+ "image1.jpg": null,
21
+ "image3.jpg": null,
22
+ "image4.jpg": null,
23
+ "image5.jpg": null,
24
+ };
25
+ class Image extends file_1.File {
26
+ getTypeName() {
27
+ return "image";
28
+ }
29
+ getExampleValue(context) {
30
+ return __awaiter(this, void 0, void 0, function* () {
31
+ const keys = Object.keys(example_image_promises);
32
+ const key = keys[Math.floor(Math.random() * keys.length)];
33
+ if (!example_image_promises[key]) {
34
+ example_image_promises[key] = context.encode_file({
35
+ type: "path",
36
+ path: locreq.resolve(`resources/${key}`),
37
+ }, true);
38
+ }
39
+ return example_image_promises[key];
40
+ });
41
+ }
42
+ }
43
+ exports.Image = Image;
44
+ //# sourceMappingURL=image.js.map
@@ -0,0 +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,IAAI,sBAAsB,GAA2C;IACpE,YAAY,EAAE,IAAI;IAClB,YAAY,EAAE,IAAI;IAClB,YAAY,EAAE,IAAI;IAClB,YAAY,EAAE,IAAI;CAClB,CAAC;AAEF,MAAa,KAAM,SAAQ,WAAY;IACtC,WAAW;QACV,OAAO,OAAO,CAAC;IAChB,CAAC;IAEK,eAAe,CAAC,OAAmB;;YACxC,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAAC;YACjD,MAAM,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;YAC1D,IAAI,CAAC,sBAAsB,CAAC,GAAG,CAAC,EAAE;gBACjC,sBAAsB,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,WAAW,CAChD;oBACC,IAAI,EAAE,MAAM;oBACZ,IAAI,EAAE,MAAM,CAAC,OAAO,CAAC,aAAa,GAAG,EAAE,CAAC;iBACxC,EACD,IAAI,CACJ,CAAC;aACF;YACD,OAAO,sBAAsB,CAAC,GAAG,CAAoB,CAAC;QACvD,CAAC;KAAA;CACD;AAnBD,sBAmBC"}
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.List = void 0;
13
+ const ts_predicates_1 = require("@sealcode/ts-predicates");
14
+ const component_argument_1 = require("./component-argument");
15
+ class List extends component_argument_1.ComponentArgument {
16
+ constructor(item_type) {
17
+ super();
18
+ this.item_type = item_type;
19
+ item_type.parent_argument = this;
20
+ }
21
+ getTypeName() {
22
+ return "list";
23
+ }
24
+ getEmptyValue() {
25
+ return [];
26
+ }
27
+ getExampleValue(context) {
28
+ const _super = Object.create(null, {
29
+ getExampleValue: { get: () => super.getExampleValue }
30
+ });
31
+ return __awaiter(this, void 0, void 0, function* () {
32
+ if (this.example_values.length) {
33
+ return _super.getExampleValue.call(this, context);
34
+ }
35
+ else {
36
+ const count = Math.floor(Math.random() * 5);
37
+ const result = [];
38
+ for (let i = 0; i < count; i++) {
39
+ result.push(this.item_type.getExampleValue(context));
40
+ }
41
+ return (yield Promise.all(result));
42
+ }
43
+ });
44
+ }
45
+ countWords(value) {
46
+ return value.reduce((acc, item) => acc + this.item_type.countWords(item), 0);
47
+ }
48
+ parseFormInput(context, input, arg_name) {
49
+ return __awaiter(this, void 0, void 0, function* () {
50
+ if (!(0, ts_predicates_1.is)(input, ts_predicates_1.predicates.array(ts_predicates_1.predicates.object)) &&
51
+ !(0, ts_predicates_1.is)(input, ts_predicates_1.predicates.object)) {
52
+ throw new Error(`$.${arg_name} is not a list or object`);
53
+ }
54
+ const values = Array.isArray(input) ? input : Object.values(input);
55
+ let array_result = yield Promise.all(values.map((value, index) => __awaiter(this, void 0, void 0, function* () {
56
+ const result = yield this.item_type.parseFormInput(context, value, `${arg_name}[${index}]`);
57
+ return result;
58
+ })));
59
+ if (this.item_type.getTypeName() != "list") {
60
+ array_result = array_result.flat();
61
+ }
62
+ return array_result.filter((e) => e !== null);
63
+ });
64
+ }
65
+ }
66
+ exports.List = List;
67
+ //# sourceMappingURL=list.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"list.js","sourceRoot":"","sources":["../../src/component-arguments/list.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2DAAyD;AAGzD,6DAG8B;AAE9B,MAAa,IAAQ,SAAQ,sCAA2B;IACvD,YAAmB,SAA+B;QACjD,KAAK,EAAE,CAAC;QADU,cAAS,GAAT,SAAS,CAAsB;QAEjD,SAAS,CAAC,eAAe,GAAG,IAAI,CAAC;IAClC,CAAC;IAED,WAAW;QACV,OAAO,MAAM,CAAC;IACf,CAAC;IAED,aAAa;QACZ,OAAO,EAAE,CAAC;IACX,CAAC;IAEK,eAAe,CAAC,OAAmB;;;;;YACxC,IAAI,IAAI,CAAC,cAAc,CAAC,MAAM,EAAE;gBAC/B,OAAO,OAAM,eAAe,YAAC,OAAO,EAAE;aACtC;iBAAM;gBACN,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC;gBAC5C,MAAM,MAAM,GAAG,EAA4B,CAAC;gBAC5C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,EAAE,CAAC,EAAE,EAAE;oBAC/B,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC,CAAC;iBACrD;gBACD,OAAO,CAAC,MAAM,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAa,CAAC;aAC/C;QACF,CAAC;KAAA;IAED,UAAU,CAAC,KAAe;QACzB,OAAO,KAAK,CAAC,MAAM,CAClB,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE,CAAC,GAAG,GAAG,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,IAAI,CAAC,EACpD,CAAC,CACD,CAAC;IACH,CAAC;IAEK,cAAc,CACnB,OAAmB,EACnB,KAAc,EACd,QAAgB;;YAEhB,IACC,CAAC,IAAA,kBAAE,EAAC,KAAK,EAAE,0BAAU,CAAC,KAAK,CAAC,0BAAU,CAAC,MAAM,CAAC,CAAC;gBAC/C,CAAC,IAAA,kBAAE,EAAC,KAAK,EAAE,0BAAU,CAAC,MAAM,CAAC,EAC5B;gBACD,MAAM,IAAI,KAAK,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;AA7DD,oBA6DC"}
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MarkdownArgument = void 0;
4
+ const ts_predicates_1 = require("@sealcode/ts-predicates");
5
+ const component_argument_1 = require("./component-argument");
6
+ class MarkdownArgument extends component_argument_1.ComponentArgument {
7
+ constructor() {
8
+ super(...arguments);
9
+ this.example_values = [
10
+ `*Lorem ipsum* dolor sit amet, **consectetur adipiscing elit**, sed [do eiusmod](#) tempor incididunt ut labore et dolore magna aliqua. Posuere lorem ipsum dolor sit amet consectetur adipiscing elit. Porttitor massa id neque aliquam vestibulum. Turpis egestas pretium aenean pharetra.
11
+
12
+ Ullamcorper dignissim cras tincidunt lobortis feugiat vivamus at augue. Tellus cras adipiscing enim eu turpis egestas. Sagittis id consectetur purus ut faucibus pulvinar elementum. Pulvinar etiam non quam lacus suspendisse. Viverra adipiscing at in tellus integer feugiat scelerisque. Ultricies leo integer malesuada nunc vel risus commodo. Morbi leo urna molestie at elementum. Justo laoreet sit amet cursus sit amet. `,
13
+ `**Duis ut diam quam nulla**.
14
+
15
+ Lectus mauris *ultrices* eros [in cursus turpis massa](#).
16
+
17
+ Pulvinar neque laoreet suspendisse interdum consectetur. Orci phasellus egestas tellus rutrum tellus.`,
18
+ ];
19
+ }
20
+ getTypeName() {
21
+ return "markdown";
22
+ }
23
+ getEmptyValue() {
24
+ return "";
25
+ }
26
+ countWords(value) {
27
+ return value.toString().split(" ").length;
28
+ }
29
+ parseFormInput(_, input) {
30
+ if ((0, ts_predicates_1.is)(input, ts_predicates_1.predicates.string)) {
31
+ return input;
32
+ }
33
+ else {
34
+ return null;
35
+ }
36
+ }
37
+ }
38
+ exports.MarkdownArgument = MarkdownArgument;
39
+ //# sourceMappingURL=markdown.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"markdown.js","sourceRoot":"","sources":["../../src/component-arguments/markdown.ts"],"names":[],"mappings":";;;AAAA,2DAAyD;AAGzD,6DAAyD;AAEzD,MAAa,gBAAiB,SAAQ,sCAAyB;IAA/D;;QAaC,mBAAc,GAAG;YAChB;;oaAEka;YACla;;;;sGAIoG;SACpG,CAAC;IAYH,CAAC;IAjCA,WAAW;QACV,OAAO,UAAU,CAAC;IACnB,CAAC;IAED,aAAa;QACZ,OAAO,EAAE,CAAC;IACX,CAAC;IAED,UAAU,CAAC,KAAa;QACvB,OAAO,KAAK,CAAC,QAAQ,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC;IAC3C,CAAC;IAaD,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;AAlCD,4CAkCC"}