@sealcode/sealgen 0.8.52 → 0.9.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.
Files changed (95) hide show
  1. package/@types/forms/controls/array.d.ts +1 -1
  2. package/@types/forms/controls/checkbox-group.d.ts +1 -1
  3. package/@types/forms/controls/collapsible-field-group.d.ts +1 -1
  4. package/@types/forms/controls/derived-frame.d.ts +1 -0
  5. package/@types/forms/controls/dropdown.d.ts +2 -2
  6. package/@types/forms/controls/form-field-control.d.ts +1 -1
  7. package/@types/forms/controls/html.d.ts +1 -1
  8. package/@types/forms/controls/multiple-files.d.ts +1 -1
  9. package/@types/forms/controls/number.d.ts +1 -1
  10. package/@types/forms/controls/simple-input.d.ts +1 -1
  11. package/@types/forms/controls/tickable.d.ts +1 -1
  12. package/@types/forms/fields/field.d.ts +6 -6
  13. package/@types/forms/fields/file.d.ts +1 -1
  14. package/@types/forms/form.d.ts +7 -7
  15. package/@types/index.d.ts +1 -0
  16. package/@types/page/list.d.ts +13 -17
  17. package/@types/page/mountable-with-fields.d.ts +2 -2
  18. package/@types/page/props-parser.d.ts +1 -1
  19. package/@types/page/sealious-list.d.ts +18 -0
  20. package/@types/utils/utils.d.ts +3 -3
  21. package/lib/add-collection.js +7 -7
  22. package/lib/add-route.js +8 -8
  23. package/lib/add-route.test.js +4 -4
  24. package/lib/build.js +44 -11
  25. package/lib/components/components.js +5 -1
  26. package/lib/components/tabs.js +2 -2
  27. package/lib/components/toggle-modal.js +2 -2
  28. package/lib/find-scss-includes.js +3 -3
  29. package/lib/forms/controls/array.js +5 -5
  30. package/lib/forms/controls/big-radio-group.js +2 -2
  31. package/lib/forms/controls/checkboxed-list-input.js +3 -3
  32. package/lib/forms/controls/collapsible-field-group.js +1 -1
  33. package/lib/forms/controls/controls.js +5 -1
  34. package/lib/forms/controls/derived-frame.js +3 -3
  35. package/lib/forms/controls/derived.js +2 -2
  36. package/lib/forms/controls/dropdown.js +2 -2
  37. package/lib/forms/controls/editable-collection-subset.js +3 -3
  38. package/lib/forms/controls/field-group.js +1 -1
  39. package/lib/forms/controls/file.js +1 -1
  40. package/lib/forms/controls/hidden-input.js +1 -1
  41. package/lib/forms/controls/multiple-files.js +5 -5
  42. package/lib/forms/controls/multiple-photos.js +1 -1
  43. package/lib/forms/controls/photo.js +1 -1
  44. package/lib/forms/controls/simple-input.js +2 -2
  45. package/lib/forms/controls/tickable.js +3 -3
  46. package/lib/forms/fields/boolean.js +3 -3
  47. package/lib/forms/fields/checkboxed-list.js +3 -3
  48. package/lib/forms/fields/enum-multiple.js +3 -3
  49. package/lib/forms/fields/enum.js +2 -2
  50. package/lib/forms/fields/field.js +6 -2
  51. package/lib/forms/fields/file.js +6 -6
  52. package/lib/forms/fields/number.js +5 -5
  53. package/lib/forms/fields/pick-from-list.js +1 -1
  54. package/lib/forms/fields/regexp.js +2 -2
  55. package/lib/forms/fields/simple-form-field.js +4 -4
  56. package/lib/forms/form.js +9 -9
  57. package/lib/forms/form.test.js +12 -12
  58. package/lib/forms/multiform.js +5 -5
  59. package/lib/forms/multiform.test.js +26 -26
  60. package/lib/generate-collections.js +9 -5
  61. package/lib/generate-routes.js +13 -9
  62. package/lib/index.js +6 -1
  63. package/lib/make-env.js +1 -1
  64. package/lib/make-hidden-inputs.js +3 -3
  65. package/lib/page/list.js +85 -65
  66. package/lib/page/mountable-with-fields.js +2 -2
  67. package/lib/page/page.js +1 -1
  68. package/lib/page/sealious-list.js +53 -0
  69. package/lib/page/stateful-page.js +9 -9
  70. package/lib/templates/form.js +1 -1
  71. package/lib/templates/list.js +10 -9
  72. package/lib/templates/multiform.js +1 -1
  73. package/lib/templates/page.js +1 -1
  74. package/lib/templates/route-test.js +1 -1
  75. package/lib/templates/stateful-page.js +1 -1
  76. package/lib/test_utils/locator_is_visible.js +1 -1
  77. package/lib/utils/exec.js +1 -1
  78. package/lib/utils/import-path.js +2 -2
  79. package/lib/utils/input-wrapper.js +1 -1
  80. package/lib/utils/list-collections.js +2 -2
  81. package/lib/utils/prettier.js +6 -2
  82. package/lib/utils/question.js +1 -1
  83. package/lib/utils/render-attributes.js +1 -1
  84. package/lib/utils/utils.js +5 -1
  85. package/lib/utils/walk.js +1 -1
  86. package/package.json +2 -2
  87. package/src/add-route.ts +1 -1
  88. package/src/build.ts +56 -1
  89. package/src/generate-collections.ts +1 -1
  90. package/src/generate-routes.ts +1 -1
  91. package/src/index.ts +1 -0
  92. package/src/page/list.ts +106 -96
  93. package/src/page/sealious-list.ts +76 -0
  94. package/src/templates/list.ts +8 -7
  95. package/src/utils/import-path.ts +1 -1
@@ -8,7 +8,7 @@ import { FormDataValue } from "../form";
8
8
  import { FormControl } from "./controls";
9
9
  import { FormControlContext } from "./form-control";
10
10
  import { FormFieldControl } from "./form-field-control";
11
- export declare type UnboundControlStorage<F extends {
11
+ export type UnboundControlStorage<F extends {
12
12
  new (...args: any): FormFieldControl;
13
13
  } = {
14
14
  new (...args: any): FormFieldControl;
@@ -3,7 +3,7 @@ import { EnumMultipleField, FormField } from "../fields/field";
3
3
  import { CheckboxWithValue } from "./checkbox";
4
4
  import { FormFieldControl } from "./controls";
5
5
  import { FormControlContext } from "./form-control";
6
- export declare type DefaultCheckboxOptions = {
6
+ export type DefaultCheckboxOptions = {
7
7
  id?: string;
8
8
  label?: string;
9
9
  hide_errors?: boolean;
@@ -1,7 +1,7 @@
1
1
  import { FlatTemplatable } from "tempstream";
2
2
  import { FieldGroup } from "./field-group";
3
3
  import { FormControl } from "./form-control";
4
- declare type CollapsibleFieldGroupOptions = {
4
+ type CollapsibleFieldGroupOptions = {
5
5
  label?: string;
6
6
  classes?: string[];
7
7
  openOnStart?: boolean;
@@ -1,4 +1,5 @@
1
1
  /// <reference types="node" />
2
+ /// <reference types="node" />
2
3
  /// <reference types="koa__router" />
3
4
  import Router from "@koa/router";
4
5
  import { Context } from "koa";
@@ -4,12 +4,12 @@ import { FormField, PickFromListField } from "../fields/field";
4
4
  import { FormDataValue } from "../form";
5
5
  import { FormControlContext } from "./form-control";
6
6
  import { SimpleInput } from "./simple-input";
7
- export declare type DropdownOptions = {
7
+ export type DropdownOptions = {
8
8
  label: string;
9
9
  autosubmit?: boolean;
10
10
  autocomplete?: boolean;
11
11
  };
12
- export declare type DropdownOption = {
12
+ export type DropdownOption = {
13
13
  value: string;
14
14
  label: string;
15
15
  };
@@ -2,7 +2,7 @@ import { FlatTemplatable } from "tempstream";
2
2
  import { FormField } from "../fields/field";
3
3
  import { FieldValueType } from "../form";
4
4
  import { FormControl, FormControlContext } from "./form-control";
5
- export declare type FormFieldsToTypes<FormFields extends readonly FormField[]> = {
5
+ export type FormFieldsToTypes<FormFields extends readonly FormField[]> = {
6
6
  [Index in keyof FormFields]: FormFields[Index] extends FormField ? FieldValueType<FormFields[Index]> : never;
7
7
  };
8
8
  export declare abstract class FormFieldControl extends FormControl {
@@ -1,7 +1,7 @@
1
1
  import { FlatTemplatable } from "tempstream";
2
2
  import { FormControl } from "./controls";
3
3
  import { FormControlContext } from "./form-control";
4
- declare type Renderer = ((fctx: FormControlContext) => FlatTemplatable) | FlatTemplatable;
4
+ type Renderer = ((fctx: FormControlContext) => FlatTemplatable) | FlatTemplatable;
5
5
  export declare class HTML extends FormControl {
6
6
  role: "decoration" | "submit";
7
7
  renderer: Renderer;
@@ -7,7 +7,7 @@ import { FlatTemplatable } from "tempstream";
7
7
  import { MultipleFiles as MultipleFilesField } from "../fields/multiple-files";
8
8
  import { FormFieldControl } from "./form-field-control";
9
9
  import { FormControlContext } from "./form-control";
10
- export declare type MultipleFilesOptions = {
10
+ export type MultipleFilesOptions = {
11
11
  label?: string;
12
12
  uploadLabel?: string;
13
13
  getAdditionalFields: (ctx: Context, file: SealiousFile) => Promise<Record<string, unknown>>;
@@ -1,7 +1,7 @@
1
1
  import { NumberField } from "../fields/field";
2
2
  import { FormControlContext } from "./form-control";
3
3
  import { SimpleInput, SimpleInputOptions } from "./simple-input";
4
- export declare type NumberOptions = SimpleInputOptions & Partial<{
4
+ export type NumberOptions = SimpleInputOptions & Partial<{
5
5
  step: number;
6
6
  }>;
7
7
  export declare class Number extends SimpleInput<number | null> {
@@ -4,7 +4,7 @@ import { FormField } from "../fields/field";
4
4
  import { FormDataValue } from "../form";
5
5
  import { FormFieldControl } from "./controls";
6
6
  import { FormControlContext } from "./form-control";
7
- export declare type SimpleInputOptions = {
7
+ export type SimpleInputOptions = {
8
8
  id?: string;
9
9
  label?: string;
10
10
  autocomplete?: boolean;
@@ -4,7 +4,7 @@ import { FormField } from "../fields/field";
4
4
  import { FormDataValue } from "../form";
5
5
  import { FormFieldControl } from "./controls";
6
6
  import { FormControlContext } from "./form-control";
7
- export declare type TickableOptions = {
7
+ export type TickableOptions = {
8
8
  id?: string;
9
9
  name?: string;
10
10
  label?: string;
@@ -1,18 +1,18 @@
1
1
  import { Predicate, predicates } from "@sealcode/ts-predicates";
2
2
  import { Context } from "koa";
3
3
  import { FormDataValue } from "../form";
4
- export declare type FormFieldValidationResponse = {
4
+ export type FormFieldValidationResponse = {
5
5
  valid: boolean;
6
6
  message: string;
7
7
  };
8
- export declare type FormFieldValidationFn<ValueType> = (ctx: Context, value: ValueType, field: FormField<boolean, ValueType>) => Promise<FormFieldValidationResponse>;
9
- export declare type FieldParsedValue<T> = T extends FormField<infer R> ? R : never;
10
- export declare type GetPredicate<F extends FormField> = F extends FormField<true> ? F["predicate"] : F["predicate"] | typeof predicates.undefined;
11
- export declare type FieldsToShape<T extends Record<string, FormField>> = {
8
+ export type FormFieldValidationFn<ValueType> = (ctx: Context, value: ValueType, field: FormField<boolean, ValueType>) => Promise<FormFieldValidationResponse>;
9
+ export type FieldParsedValue<T> = T extends FormField<infer R> ? R : never;
10
+ export type GetPredicate<F extends FormField> = F extends FormField<true> ? F["predicate"] : F["predicate"] | typeof predicates.undefined;
11
+ export type FieldsToShape<T extends Record<string, FormField>> = {
12
12
  [property in keyof T]: GetPredicate<T[property]>;
13
13
  };
14
14
  export declare function fieldsToShape<Fields extends Record<string, FormField>>(obj: Fields): FieldsToShape<Fields>;
15
- export declare type FieldParseResult<T> = {
15
+ export type FieldParseResult<T> = {
16
16
  parsable: true;
17
17
  error: null;
18
18
  parsed_value: T;
@@ -2,7 +2,7 @@ import { Context } from "koa";
2
2
  import { File as SealiousFile } from "sealious";
3
3
  import { FormDataValue } from "../form";
4
4
  import { FieldParseResult, FormField } from "./field";
5
- export declare type FileContainer = {
5
+ export type FileContainer = {
6
6
  old: SealiousFile | null;
7
7
  new: SealiousFile | null;
8
8
  };
@@ -5,21 +5,21 @@ import Router from "@koa/router";
5
5
  import { FlatTemplatable } from "tempstream";
6
6
  import { FormField } from "./fields/field";
7
7
  import { Fields, MountableWithFields, PageErrorMessage } from "../page/mountable-with-fields";
8
- export declare type FormDataPrimitive = string | string[] | number | undefined;
9
- export declare type FormDataValue = FormDataPrimitive | Record<string, FormDataPrimitive> | SealiousFile;
10
- export declare type FieldValueType<F extends FormField> = F extends FormField<infer R> ? R : never;
11
- export declare type FormFieldsToValues<F extends Record<string, FormField<boolean, keyof F>>> = {
8
+ export type FormDataPrimitive = string | string[] | number | undefined;
9
+ export type FormDataValue = FormDataPrimitive | Record<string, FormDataPrimitive> | SealiousFile;
10
+ export type FieldValueType<F extends FormField> = F extends FormField<infer R> ? R : never;
11
+ export type FormFieldsToValues<F extends Record<string, FormField<boolean, keyof F>>> = {
12
12
  [Property in keyof F]: FieldValueType<F[Property]>;
13
13
  };
14
- export declare type FormMessage = {
14
+ export type FormMessage = {
15
15
  type: "info" | "success" | "error";
16
16
  text: string;
17
17
  };
18
- export declare type FormData<Fieldnames extends string = string> = {
18
+ export type FormData<Fieldnames extends string = string> = {
19
19
  raw_values: Record<Fieldnames, FormDataValue>;
20
20
  messages: FormMessage[];
21
21
  };
22
- export declare type FormReaction = {
22
+ export type FormReaction = {
23
23
  action: "stay";
24
24
  content: FlatTemplatable;
25
25
  messages?: FormMessage[];
package/@types/index.d.ts CHANGED
@@ -16,6 +16,7 @@ export * from "./forms/form";
16
16
  export * from "./page/props-parser";
17
17
  export * from "./utils/utils";
18
18
  export * from "./page/list";
19
+ export * from "./page/sealious-list";
19
20
  export * from "./utils/translate";
20
21
  export * as sanitize from "./sanitize";
21
22
  export * from "./forms/multiform";
@@ -1,16 +1,16 @@
1
1
  import { Context } from "koa";
2
- import { Collection, CollectionItem, ItemList, Context as SealiousContext } from "sealious";
3
2
  import { Templatable, FlatTemplatable } from "tempstream";
4
3
  import { Page } from "./page";
5
4
  import { ShapeToType } from "@sealcode/ts-predicates";
6
5
  import { FormControl } from "../forms/controls/controls";
7
- import { FormField, NumberField } from "../forms/fields/field";
6
+ import { FormField, NumberField, SimpleFormField } from "../forms/fields/field";
8
7
  import { FormDataValue } from "..";
9
8
  export declare const BasePagePropsShape: {};
10
- export declare type BasePageProps = ShapeToType<typeof BasePagePropsShape>;
9
+ export type BasePageProps = ShapeToType<typeof BasePagePropsShape>;
11
10
  export declare const BaseListPageFields: {
12
11
  readonly page: NumberField<1, false>;
13
12
  readonly itemsPerPage: NumberField<12, false>;
13
+ readonly sort: SimpleFormField<false>;
14
14
  };
15
15
  export declare abstract class ListPage<ItemType, F extends typeof BaseListPageFields> extends Page<F> {
16
16
  abstract getItems(ctx: Context, page: number, itemsPerPage: number, values: Record<string, FormDataValue>): Promise<ItemType[]>;
@@ -29,19 +29,15 @@ export declare abstract class ListPage<ItemType, F extends typeof BaseListPageFi
29
29
  renderPagination(ctx: Context, values: Record<string, FormDataValue>): Promise<FlatTemplatable>;
30
30
  private renderPageButton;
31
31
  getFilterValues(ctx: Context): Promise<Record<string, unknown>>;
32
+ getSort(ctx: Context): Promise<{
33
+ field: string;
34
+ order: "asc" | "desc";
35
+ } | null>;
36
+ makeSortLink(ctx: Context, field: string, order: "asc" | "desc"): string;
32
37
  renderFilters(ctx: Context): Promise<FlatTemplatable>;
33
- }
34
- export declare abstract class SealiousItemListPage<C extends Collection, F extends typeof BaseListPageFields> extends ListPage<CollectionItem<C>, F> {
35
- collection: C;
36
- constructor(collection: C);
37
- getContextForList(ctx: Context): Promise<SealiousContext>;
38
- getTotalPages(ctx: Context, itemsPerPage: number): Promise<number>;
39
- protected addFilter(ctx: Context, list: ItemList<C>): Promise<void>;
40
- makeQuery(ctx: Context): Promise<ItemList<C>>;
41
- getItems(ctx: Context, page: number, itemsPerPage: number): Promise<CollectionItem<C>[]>;
42
- renderItem(_: Context, item: CollectionItem<C>, index: number): Promise<FlatTemplatable>;
43
- canAccess: (ctx: Context) => Promise<{
44
- canAccess: boolean;
45
- message: string;
46
- }>;
38
+ renderHeading(ctx: Context, field: string, label?: string): FlatTemplatable;
39
+ renderTableHead(ctx: Context, fields: {
40
+ field: string;
41
+ label?: string;
42
+ }[]): FlatTemplatable;
47
43
  }
@@ -5,11 +5,11 @@ import { FormControl, FormControlContext } from "../forms/controls/form-control"
5
5
  import { FieldsToShape, FormField } from "../forms/fields/field";
6
6
  import { FormData, FormDataValue, FormMessage } from "../forms/form";
7
7
  import { Mountable } from "./mountable";
8
- export declare type PageErrorMessage = {
8
+ export type PageErrorMessage = {
9
9
  type: "access" | "internal";
10
10
  message: string;
11
11
  };
12
- export declare type Fields = Record<string, FormField<boolean, any>>;
12
+ export type Fields = Record<string, FormField<boolean, any>>;
13
13
  export declare abstract class MountableWithFields<F extends Fields = Fields> extends Mountable {
14
14
  fields: F;
15
15
  field_names_prefix: string;
@@ -1,7 +1,7 @@
1
1
  import { Context } from "koa";
2
2
  import { FormData, FormDataValue } from "..";
3
3
  import { BasePageProps } from "./list";
4
- export declare type EncodedProps = Record<string, unknown>;
4
+ export type EncodedProps = Record<string, unknown>;
5
5
  export declare abstract class PagePropsParser<PropsType> {
6
6
  abstract decode(ctx: Context): Record<string, FormDataValue>;
7
7
  abstract encode(props: Record<string, FormData>): EncodedProps;
@@ -0,0 +1,18 @@
1
+ import { Context } from "koa";
2
+ import { BaseListPageFields, ListPage } from "./list";
3
+ import { Collection, CollectionItem, ItemList, Context as SealiousContext } from "sealious";
4
+ import { FlatTemplatable } from "tempstream";
5
+ export declare abstract class SealiousItemListPage<C extends Collection, F extends typeof BaseListPageFields> extends ListPage<CollectionItem<C>, F> {
6
+ collection: C;
7
+ constructor(collection: C);
8
+ getContextForList(ctx: Context): Promise<SealiousContext>;
9
+ getTotalPages(ctx: Context, itemsPerPage: number): Promise<number>;
10
+ protected addFilter(ctx: Context, list: ItemList<C>): Promise<void>;
11
+ makeQuery(ctx: Context): Promise<ItemList<C>>;
12
+ getItems(ctx: Context, page: number, itemsPerPage: number): Promise<CollectionItem<C>[]>;
13
+ renderItem(_: Context, item: CollectionItem<C>, index: number): Promise<FlatTemplatable>;
14
+ canAccess: (ctx: Context) => Promise<{
15
+ canAccess: boolean;
16
+ message: string;
17
+ }>;
18
+ }
@@ -1,7 +1,7 @@
1
- export declare type Awaited<T> = T extends Promise<infer U> ? U : T;
2
- export declare type UnwrapArray<T> = T extends Array<infer U> ? U : T;
1
+ export type Awaited<T> = T extends Promise<infer U> ? U : T;
2
+ export type UnwrapArray<T> = T extends Array<infer U> ? U : T;
3
3
  export declare function keys<S extends string>(object: Record<S, unknown>): S[];
4
- export declare type ExtractTail<T extends any[]> = T extends [infer _, ...infer Tail] ? Tail : never;
4
+ export type ExtractTail<T extends any[]> = T extends [infer _, ...infer Tail] ? Tail : never;
5
5
  export { sleep } from "./sleep";
6
6
  export { naturalNumbers } from "./natural-numbers";
7
7
  export { UrlWithNewParams } from "./url-with-new-params";
@@ -10,22 +10,22 @@ const fs_1 = require("fs");
10
10
  const question_1 = require("./utils/question");
11
11
  const collection_1 = require("./templates/collection");
12
12
  const generate_collections_1 = require("./generate-collections");
13
- const target_locreq = locreq_1.default(process.cwd());
13
+ const target_locreq = (0, locreq_1.default)(process.cwd());
14
14
  async function addCollection() {
15
15
  const regex_pattern = /^([A-Z_$][a-zA-Z0-9_$]*)$/;
16
- const collection_name = await question_1.question('What\'s the name of the collection class (e.g. "SecretDocuments", must start with a capital letter): ', (s) => s.length > 3 && regex_pattern.test(s));
17
- const url = await question_1.question("Enter the url-friendly name for the collection (e.g. secret-documents): ", (s) => !s.includes("/") && !s.includes(" "));
16
+ const collection_name = await (0, question_1.question)('What\'s the name of the collection class (e.g. "SecretDocuments", must start with a capital letter): ', (s) => s.length > 3 && regex_pattern.test(s));
17
+ const url = await (0, question_1.question)("Enter the url-friendly name for the collection (e.g. secret-documents): ", (s) => !s.includes("/") && !s.includes(" "));
18
18
  const file_path = target_locreq.resolve(`src/back/collections/${url}.ts`);
19
- if (fs_1.existsSync(file_path)) {
19
+ if ((0, fs_1.existsSync)(file_path)) {
20
20
  // eslint-disable-next-line no-console
21
21
  console.error(`ERROR: File ${file_path} already exists.`);
22
22
  return;
23
23
  }
24
- await fs_1.promises.mkdir(path_1.resolve(file_path, "../"), { recursive: true });
25
- await fs_1.promises.writeFile(file_path, collection_1.collectionTemplate(collection_name));
24
+ await fs_1.promises.mkdir((0, path_1.resolve)(file_path, "../"), { recursive: true });
25
+ await fs_1.promises.writeFile(file_path, (0, collection_1.collectionTemplate)(collection_name));
26
26
  // eslint-disable-next-line no-console
27
27
  console.log(`${file_path} created`);
28
- await generate_collections_1.generateCollections();
28
+ await (0, generate_collections_1.generateCollections)();
29
29
  }
30
30
  exports.addCollection = addCollection;
31
31
  //# sourceMappingURL=add-collection.js.map
package/lib/add-route.js CHANGED
@@ -19,7 +19,7 @@ const prompts = require("prompts");
19
19
  const post_1 = require("./templates/post");
20
20
  const stateful_page_1 = require("./templates/stateful-page");
21
21
  async function addRoute(params, app_directory = process.cwd()) {
22
- const target_locreq = locreq_1.default(app_directory);
22
+ const target_locreq = (0, locreq_1.default)(app_directory);
23
23
  prompts.override(params);
24
24
  const response = await prompts([
25
25
  {
@@ -31,7 +31,7 @@ async function addRoute(params, app_directory = process.cwd()) {
31
31
  {
32
32
  type: "text",
33
33
  name: "url",
34
- message: "Enter a full absolute path for the new route (e.g. /admin/users/add): ",
34
+ message: "Enter a full absolute path for the new route (for example: /admin/users/:id/edit): ",
35
35
  validate: (s) => s.trim()[0] == "/" ? true : "Should start with a '/'",
36
36
  },
37
37
  {
@@ -50,8 +50,8 @@ async function addRoute(params, app_directory = process.cwd()) {
50
50
  },
51
51
  ]);
52
52
  const { action, url, mode } = response;
53
- const file_path = target_locreq.resolve(`src/back/routes/${escape_url_params_1.escape_url_params(url)}.${mode}.ts`);
54
- const test_file_path = target_locreq.resolve(`src/back/routes/${escape_url_params_1.escape_url_params(url)}.test.ts`);
53
+ const file_path = target_locreq.resolve(`src/back/routes/${(0, escape_url_params_1.escape_url_params)(url)}.${mode}.ts`);
54
+ const test_file_path = target_locreq.resolve(`src/back/routes/${(0, escape_url_params_1.escape_url_params)(url)}.test.ts`);
55
55
  const template = {
56
56
  page: page_1.pageTemplate,
57
57
  form: form_1.formTemplate,
@@ -64,19 +64,19 @@ async function addRoute(params, app_directory = process.cwd()) {
64
64
  if (!template) {
65
65
  throw new Error(`Could not get template ${mode}`);
66
66
  }
67
- if (fs_1.existsSync(file_path)) {
67
+ if ((0, fs_1.existsSync)(file_path)) {
68
68
  // eslint-disable-next-line no-console
69
69
  console.error(`ERROR: File ${file_path} already exists.`);
70
70
  return;
71
71
  }
72
- await fs_1.promises.mkdir(path_1.resolve(file_path, "../"), { recursive: true });
72
+ await fs_1.promises.mkdir((0, path_1.resolve)(file_path, "../"), { recursive: true });
73
73
  await fs_1.promises.writeFile(file_path, await template(action, file_path));
74
- await fs_1.promises.writeFile(test_file_path, route_test_1.testTemplate(action, file_path));
74
+ await fs_1.promises.writeFile(test_file_path, (0, route_test_1.testTemplate)(action, file_path));
75
75
  // eslint-disable-next-line no-console
76
76
  console.log(`${file_path} created`);
77
77
  // eslint-disable-next-line no-console
78
78
  console.log(`${test_file_path} created`);
79
- await generate_routes_1.generateRoutes();
79
+ await (0, generate_routes_1.generateRoutes)();
80
80
  }
81
81
  exports.addRoute = addRoute;
82
82
  //# sourceMappingURL=add-route.js.map
@@ -9,7 +9,7 @@ const util_1 = require("util");
9
9
  const axios_1 = __importDefault(require("axios"));
10
10
  const wait_port_1 = __importDefault(require("wait-port"));
11
11
  const get_port_1 = __importDefault(require("get-port"));
12
- const execAsync = util_1.promisify(child_process_1.exec);
12
+ const execAsync = (0, util_1.promisify)(child_process_1.exec);
13
13
  describe("add route test", () => {
14
14
  let node_pid = 0;
15
15
  const app_path = "/tmp/sealious-minimal";
@@ -31,17 +31,17 @@ describe("add route test", () => {
31
31
  console.log("\trunning add-route and building app...");
32
32
  await execAsync(`cd ${app_path} && npx sealgen add-route --url=/sample --action=Sample --mode=page && npm run build`);
33
33
  console.log("\tstarting the database...(if timeouts here, run 'docker pull mongo:4.4-bionic' to solve)");
34
- const port = await get_port_1.default();
34
+ const port = await (0, get_port_1.default)();
35
35
  await execAsync(`docker run -p ${port}:27017 --name ${container_name} -d mongo:4.4-bionic`);
36
36
  console.log("\trunning app and making request to the generated url...");
37
37
  const env = { ...process.env, SEALIOUS_MONGO_PORT: port.toString() };
38
- let app_start = child_process_1.spawn(`node`, [`${app_path}/dist/back/index.js`], {
38
+ let app_start = (0, child_process_1.spawn)(`node`, [`${app_path}/dist/back/index.js`], {
39
39
  env,
40
40
  });
41
41
  if (app_start.pid == undefined)
42
42
  throw new Error("node failed to start");
43
43
  node_pid = app_start.pid;
44
- await wait_port_1.default({
44
+ await (0, wait_port_1.default)({
45
45
  host: "localhost",
46
46
  port: 8080,
47
47
  output: "silent",
package/lib/build.js CHANGED
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[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);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -24,6 +28,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
24
28
  Object.defineProperty(exports, "__esModule", { value: true });
25
29
  exports.buildProject = void 0;
26
30
  const esbuild_1 = require("esbuild");
31
+ const fs_1 = require("fs");
27
32
  const esbuild_sass_plugin_1 = require("esbuild-sass-plugin");
28
33
  const chokidar = __importStar(require("chokidar"));
29
34
  const tiny_glob_1 = __importDefault(require("tiny-glob"));
@@ -31,18 +36,46 @@ const find_scss_includes_1 = require("./find-scss-includes");
31
36
  const sleep_1 = require("./utils/sleep");
32
37
  const generate_collections_1 = require("./generate-collections");
33
38
  const generate_routes_1 = require("./generate-routes");
39
+ const generate_names = (function* generate_names() {
40
+ let base_name = "______unique_import_";
41
+ let count = 0;
42
+ while (true) {
43
+ yield base_name + count;
44
+ count++;
45
+ }
46
+ })();
34
47
  async function build_ts() {
35
- await Promise.all([generate_collections_1.generateCollections(), generate_routes_1.generateRoutes()]);
36
- const entryPoints = (await tiny_glob_1.default("./src/back/**/*.ts")).filter((path) => !path.includes(".#"));
48
+ await Promise.all([(0, generate_collections_1.generateCollections)(), (0, generate_routes_1.generateRoutes)()]);
49
+ const entryPoints = (await (0, tiny_glob_1.default)("./src/back/**/*.ts")).filter((path) => !path.includes(".#"));
37
50
  try {
38
- await esbuild_1.build({
51
+ await (0, esbuild_1.build)({
39
52
  entryPoints,
40
53
  sourcemap: true,
41
54
  outdir: "./dist/back",
42
55
  logLevel: "info",
43
56
  platform: "node",
44
57
  target: "es2022",
45
- format: "cjs",
58
+ format: "esm",
59
+ plugins: [
60
+ {
61
+ name: "remove-named-imports",
62
+ setup(build) {
63
+ build.onLoad({ filter: /.*/ }, async ({ path }) => {
64
+ const named_and_default_regex = /^import\s+((\S+),\s+)?({\s*[^}]+})\s+from\s+("[^"]+");\s*$/gm;
65
+ const old_content = await fs_1.promises.readFile(path, "utf-8");
66
+ const contents = old_content.replace(named_and_default_regex, (entire_string, default_import_name, _, all_named, module_path) => {
67
+ const new_name = generate_names.next().value;
68
+ return `import * as ${new_name} from ${module_path}; ${default_import_name
69
+ ? `const ${default_import_name.replace(",", "")} = ${new_name}`
70
+ : ""}; const ${all_named.replaceAll(/\s+as\s+/g, ": ")} = ${/\s+default\s+as/.test(all_named)
71
+ ? `${new_name};`
72
+ : `${new_name}.default || ${new_name};`}`;
73
+ });
74
+ return { contents, loader: "ts" };
75
+ });
76
+ },
77
+ },
78
+ ],
46
79
  });
47
80
  }
48
81
  catch (e) {
@@ -60,14 +93,14 @@ async function complex_build(watch) {
60
93
  return;
61
94
  if (path.endsWith(".scss") && !path.endsWith("/includes.scss")) {
62
95
  // refresh the list of all scss files in includes.scss
63
- await find_scss_includes_1.generateScssIncludes();
96
+ await (0, find_scss_includes_1.generateScssIncludes)();
64
97
  try {
65
98
  await scss_build?.rebuild?.();
66
99
  console.log(`Built main.scss [on ${path}]`);
67
100
  }
68
101
  catch (e) {
69
102
  console.error(e.message);
70
- await sleep_1.sleep(200);
103
+ await (0, sleep_1.sleep)(200);
71
104
  scss_build
72
105
  ?.rebuild?.()
73
106
  // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
@@ -83,21 +116,21 @@ async function complex_build(watch) {
83
116
  }
84
117
  });
85
118
  }
86
- await find_scss_includes_1.generateScssIncludes();
87
- scss_build = await esbuild_1.build({
119
+ await (0, find_scss_includes_1.generateScssIncludes)();
120
+ scss_build = await (0, esbuild_1.build)({
88
121
  entryPoints: ["./src/main.scss"],
89
122
  sourcemap: true,
90
123
  outfile: "./public/dist/style.css",
91
124
  logLevel: "info",
92
125
  incremental: watch,
93
- plugins: [esbuild_sass_plugin_1.sassPlugin()],
126
+ plugins: [(0, esbuild_sass_plugin_1.sassPlugin)()],
94
127
  });
95
128
  await build_ts();
96
129
  watch && scss_build?.rebuild?.();
97
130
  }
98
131
  async function buildProject({ watch, }) {
99
132
  try {
100
- await esbuild_1.build({
133
+ await (0, esbuild_1.build)({
101
134
  entryPoints: ["./src/front/index.ts"],
102
135
  sourcemap: true,
103
136
  outfile: "./public/dist/bundle.js",
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[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);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -52,7 +52,7 @@ const style = (hide_tabs_width) => /* HTML */ `<style>
52
52
  }
53
53
  </style>`;
54
54
  function tabs(tabs, selected_tab_style = "font-weight: bold;", selected_index = 0, hide_tabs_width = 0) {
55
- return /* HTML */ tempstream_1.tempstream `${style(hide_tabs_width)}
55
+ return /* HTML */ (0, tempstream_1.tempstream) `${style(hide_tabs_width)}
56
56
  ${Object.keys(tabs)
57
57
  .map((tab_title, index) => {
58
58
  const id = name_to_id(tab_title);
@@ -71,7 +71,7 @@ function tabs(tabs, selected_tab_style = "font-weight: bold;", selected_index =
71
71
  .join("\n")}
72
72
  ${Object.entries(tabs).map(([title, content]) => {
73
73
  const id = name_to_id(title);
74
- return /* HTML */ tempstream_1.tempstream `<div class="tab-label tab-label--mobile">
74
+ return /* HTML */ (0, tempstream_1.tempstream) `<div class="tab-label tab-label--mobile">
75
75
  ${title}
76
76
  </div>
77
77
  <div class="tab-content tab-content--${id}">${content}</div>
@@ -5,8 +5,8 @@ const tempstream_1 = require("tempstream");
5
5
  const utils_1 = require("../utils/utils");
6
6
  function toggleModal(options) {
7
7
  const { contentWrapped, contentUnwrapped, name } = options;
8
- const id = utils_1.makeSlug(name);
9
- return tempstream_1.tempstream /* HTML */ `<style>
8
+ const id = (0, utils_1.makeSlug)(name);
9
+ return (0, tempstream_1.tempstream /* HTML */) `<style>
10
10
  .toggle-modal__wrapped {
11
11
  display: none;
12
12
  }
@@ -8,14 +8,14 @@ const fs_1 = require("fs");
8
8
  const locreq_1 = __importDefault(require("locreq"));
9
9
  const path_1 = require("path");
10
10
  const walk_1 = require("./utils/walk");
11
- const target_locreq = locreq_1.default(process.cwd());
11
+ const target_locreq = (0, locreq_1.default)(process.cwd());
12
12
  async function generateScssIncludes() {
13
- const files = await Promise.all((await walk_1.walkDir(target_locreq.resolve("src/")))
13
+ const files = await Promise.all((await (0, walk_1.walkDir)(target_locreq.resolve("src/")))
14
14
  .filter((f) => f.endsWith(".scss") &&
15
15
  !f.endsWith("/main.scss") &&
16
16
  !f.endsWith("/includes.scss") &&
17
17
  !f.includes(".#"))
18
- .map((fullpath) => path_1.relative(target_locreq.resolve("src/"), fullpath)));
18
+ .map((fullpath) => (0, path_1.relative)(target_locreq.resolve("src/"), fullpath)));
19
19
  await fs_1.promises.writeFile(target_locreq.resolve("src/includes.scss"), `// DO NOT EDIT! This file is generated automaticaly with npx sealgen generate-scss-includes
20
20
 
21
21
  @import "../node_modules/@sealcode/sealgen/src/forms/forms.scss";
@@ -61,7 +61,7 @@ class StructuredArray extends form_field_control_1.FormFieldControl {
61
61
  inner_form_id: this.getInnerFormID(),
62
62
  field_name: field.name,
63
63
  }));
64
- return tempstream_1.tempstream `${new constructor(field, params).render({
64
+ return (0, tempstream_1.tempstream) `${new constructor(field, params).render({
65
65
  ...fctx,
66
66
  data: { [field.name]: item[field_name] },
67
67
  })}${hidden_shadow.render({
@@ -75,7 +75,7 @@ class StructuredArray extends form_field_control_1.FormFieldControl {
75
75
  }
76
76
  }
77
77
  async renderItem(ctx, form_id, item, index) {
78
- return tempstream_1.tempstream /* HTML */ `<div>
78
+ return (0, tempstream_1.tempstream /* HTML */) `<div>
79
79
  ${this.item_controls.map((control) => this.renderItemControl(ctx, form_id, control, item, index))}
80
80
  <input
81
81
  type="submit"
@@ -92,7 +92,7 @@ class StructuredArray extends form_field_control_1.FormFieldControl {
92
92
  }
93
93
  async _render(ctx, form_id, raw_values) {
94
94
  const items = await this.getItems(ctx, raw_values);
95
- return tempstream_1.tempstream /* HTML */ `<turbo-frame id="${this.getFrameID()}">
95
+ return (0, tempstream_1.tempstream /* HTML */) `<turbo-frame id="${this.getFrameID()}">
96
96
  Reverse Single Reference
97
97
  ${items.map((item, index) => this.renderItem(ctx, form_id, item, index))}
98
98
  <form id="${this.getInnerFormID()}" method="POST"></form>
@@ -120,12 +120,12 @@ class StructuredArray extends form_field_control_1.FormFieldControl {
120
120
  throw new Error("Missing form_id query param");
121
121
  }
122
122
  const item = await this.field.sealious_field.collection.getByID(ctx.$context, await this.getTargetItemID(ctx));
123
- if (!ts_predicates_1.hasShape({ action: ts_predicates_1.predicates.object }, ctx.$body)) {
123
+ if (!(0, ts_predicates_1.hasShape)({ action: ts_predicates_1.predicates.object }, ctx.$body)) {
124
124
  throw new Error("Missing action param");
125
125
  }
126
126
  const field_data = ctx.$body[this.field.name] || { data: [] };
127
127
  console.log({ action: field_data });
128
- if (!ts_predicates_1.hasShape({
128
+ if (!(0, ts_predicates_1.hasShape)({
129
129
  data: ts_predicates_1.predicates.array(this.field.sealious_field.value_predicate),
130
130
  }, field_data)) {
131
131
  throw new Error("missing data atribute in action description");