@sealcode/sealgen 0.19.0 → 0.19.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.
Files changed (185) hide show
  1. package/@types/forms/fields/deep-reverse-single-reference-list.d.ts +1 -5
  2. package/@types/forms/fields/file.d.ts +1 -1
  3. package/@types/forms/fields/password.d.ts +1 -2
  4. package/@types/forms/fields/simple-form-field.d.ts +4 -4
  5. package/@types/forms/fields/single-reference.d.ts +1 -1
  6. package/@types/register-external.d.ts +2 -2
  7. package/@types/templates/form.d.ts +1 -3
  8. package/@types/templates/jdd-component.d.ts +1 -1
  9. package/@types/templates/page.d.ts +1 -1
  10. package/@types/templates/shared/shared-crud-form-fields.d.ts +1 -1
  11. package/@types/templates/templates.d.ts +1 -21
  12. package/eslint.config.mjs +56 -0
  13. package/lib/add-crud.js +1 -4
  14. package/lib/add-jdd-component.js +3 -3
  15. package/lib/add-route.js +2 -2
  16. package/lib/build.js +3 -3
  17. package/lib/builders/backend-ts-builder.js +0 -1
  18. package/lib/builders/colors-builder.js +11 -8
  19. package/lib/builders/fonts-builder.js +0 -1
  20. package/lib/builders/frontend-ts-builder.js +0 -1
  21. package/lib/cli.js +2 -2
  22. package/lib/components/tabs.js +36 -36
  23. package/lib/esbuild-plugins/rewrite-asset-imports.js +7 -10
  24. package/lib/forms/controls/array.js +5 -6
  25. package/lib/forms/controls/checkboxed-list-input.js +1 -2
  26. package/lib/forms/controls/checkboxed-list-input.test.js +6 -6
  27. package/lib/forms/controls/derived-frame.js +3 -3
  28. package/lib/forms/controls/dropdown.js +1 -2
  29. package/lib/forms/controls/file.test.js +1 -1
  30. package/lib/forms/controls/form-control.js +1 -1
  31. package/lib/forms/controls/image.test.js +2 -2
  32. package/lib/forms/controls/single-reference.test.js +1 -1
  33. package/lib/forms/controls/table.js +10 -15
  34. package/lib/forms/controls/textarea.js +1 -1
  35. package/lib/forms/fields/deep-reverse-single-reference-list.js +1 -1
  36. package/lib/forms/fields/field.test.js +3 -3
  37. package/lib/forms/fields/file.js +1 -1
  38. package/lib/forms/fields/file.test.js +1 -1
  39. package/lib/forms/fields/password.js +1 -1
  40. package/lib/forms/fields/simple-form-field.js +4 -3
  41. package/lib/forms/fields/single-reference.js +1 -1
  42. package/lib/forms/fields/structured-array.js +0 -2
  43. package/lib/forms/fields/table.js +1 -1
  44. package/lib/forms/form.js +0 -1
  45. package/lib/forms/form.test.js +2 -3
  46. package/lib/forms/multiform.js +6 -7
  47. package/lib/forms/multiform.test.js +2 -2
  48. package/lib/generate-collections.js +2 -3
  49. package/lib/generate-components.js +2 -3
  50. package/lib/generate-routes.js +3 -5
  51. package/lib/generate-routes.test.js +7 -16
  52. package/lib/generate-stimulus.js +4 -5
  53. package/lib/get-fonts.js +29 -27
  54. package/lib/make-env.js +1 -1
  55. package/lib/make-hidden-inputs.js +4 -4
  56. package/lib/mount.js +0 -1
  57. package/lib/notifier.js +3 -3
  58. package/lib/page/list.js +5 -7
  59. package/lib/page/mountable.js +0 -1
  60. package/lib/page/page.js +0 -1
  61. package/lib/register-external.js +4 -4
  62. package/lib/templates/form.js +1 -1
  63. package/lib/templates/jdd-component.js +1 -1
  64. package/lib/templates/jdd-editor.js +1 -1
  65. package/lib/templates/page.js +1 -1
  66. package/lib/templates/shared/collection-create-form.js +4 -5
  67. package/lib/templates/shared/collection-edit-form.js +4 -5
  68. package/lib/templates/shared/collection-list.js +2 -2
  69. package/lib/templates/shared/shared-crud-form-fields.js +3 -5
  70. package/lib/test_utils/exec_async.js +3 -3
  71. package/lib/test_utils/test-on-real-app.js +9 -11
  72. package/lib/utils/write-file.js +1 -1
  73. package/package.json +9 -8
  74. package/src/add-collection.ts +1 -3
  75. package/src/add-crud.ts +2 -7
  76. package/src/add-jdd-component.ts +4 -5
  77. package/src/add-route.ts +3 -6
  78. package/src/build.ts +3 -3
  79. package/src/builders/backend-ts-builder.ts +0 -1
  80. package/src/builders/builder.ts +4 -1
  81. package/src/builders/colors-builder.ts +11 -9
  82. package/src/builders/css-builder.ts +4 -1
  83. package/src/builders/fonts-builder.ts +0 -1
  84. package/src/builders/frontend-ts-builder.ts +0 -1
  85. package/src/cli.ts +2 -2
  86. package/src/components/tabs.ts +38 -37
  87. package/src/components/toggle-modal.ts +1 -1
  88. package/src/controllers/table-add-button.stimulus.ts +1 -1
  89. package/src/esbuild-plugins/rewrite-asset-imports.ts +7 -10
  90. package/src/forms/controls/array.ts +12 -16
  91. package/src/forms/controls/autocomplete.ts +1 -1
  92. package/src/forms/controls/big-radio-group.ts +2 -2
  93. package/src/forms/controls/checkbox-group.ts +1 -1
  94. package/src/forms/controls/checkboxed-list-input.test.ts +6 -6
  95. package/src/forms/controls/checkboxed-list-input.ts +18 -22
  96. package/src/forms/controls/derived-frame.ts +11 -10
  97. package/src/forms/controls/derived.ts +6 -5
  98. package/src/forms/controls/dropdown.ts +8 -11
  99. package/src/forms/controls/editable-collection-subset.ts +2 -1
  100. package/src/forms/controls/field-group.ts +1 -1
  101. package/src/forms/controls/file.test.ts +1 -1
  102. package/src/forms/controls/file.ts +4 -7
  103. package/src/forms/controls/form-control.ts +1 -1
  104. package/src/forms/controls/hidden-input.ts +1 -0
  105. package/src/forms/controls/html.ts +1 -0
  106. package/src/forms/controls/image.test.ts +2 -2
  107. package/src/forms/controls/image.ts +1 -1
  108. package/src/forms/controls/multiple-files.ts +5 -7
  109. package/src/forms/controls/multiple-images.ts +1 -1
  110. package/src/forms/controls/simple-input.ts +8 -4
  111. package/src/forms/controls/single-reference.test.ts +1 -1
  112. package/src/forms/controls/single-reference.ts +1 -1
  113. package/src/forms/controls/table.ts +16 -21
  114. package/src/forms/controls/textarea.ts +1 -1
  115. package/src/forms/controls/tickable.ts +0 -2
  116. package/src/forms/fields/boolean.ts +4 -1
  117. package/src/forms/fields/checkboxed-list.ts +1 -1
  118. package/src/forms/fields/collection-field.ts +5 -2
  119. package/src/forms/fields/color.ts +1 -1
  120. package/src/forms/fields/coordinates.ts +2 -2
  121. package/src/forms/fields/deep-reverse-single-reference-list.ts +2 -8
  122. package/src/forms/fields/deep-reverse-single-reference-table.ts +1 -1
  123. package/src/forms/fields/email.ts +1 -1
  124. package/src/forms/fields/enum-multiple-sealious.ts +1 -1
  125. package/src/forms/fields/existing-sealious-value.ts +1 -1
  126. package/src/forms/fields/field.test.ts +3 -3
  127. package/src/forms/fields/field.ts +6 -5
  128. package/src/forms/fields/file.test.ts +1 -1
  129. package/src/forms/fields/file.ts +2 -2
  130. package/src/forms/fields/float.ts +1 -1
  131. package/src/forms/fields/get-field-for-sealious.ts +97 -64
  132. package/src/forms/fields/int.ts +1 -1
  133. package/src/forms/fields/number.ts +2 -2
  134. package/src/forms/fields/password.ts +2 -6
  135. package/src/forms/fields/pick-from-list-sealious.ts +1 -1
  136. package/src/forms/fields/pick-from-list.ts +1 -1
  137. package/src/forms/fields/proxy-field.ts +1 -0
  138. package/src/forms/fields/simple-form-field.ts +19 -9
  139. package/src/forms/fields/single-reference.ts +2 -2
  140. package/src/forms/fields/structured-array.ts +2 -6
  141. package/src/forms/fields/table.ts +7 -15
  142. package/src/forms/fields/text.ts +1 -1
  143. package/src/forms/fields/url.ts +1 -1
  144. package/src/forms/form-types.ts +3 -4
  145. package/src/forms/form.test.ts +2 -3
  146. package/src/forms/form.ts +5 -7
  147. package/src/forms/multiform.test.ts +6 -6
  148. package/src/forms/multiform.ts +10 -10
  149. package/src/generate-collections.ts +2 -3
  150. package/src/generate-components.ts +2 -3
  151. package/src/generate-routes.test.ts +7 -16
  152. package/src/generate-routes.ts +6 -10
  153. package/src/generate-stimulus.ts +4 -6
  154. package/src/get-fonts.ts +32 -30
  155. package/src/make-env.ts +1 -1
  156. package/src/make-hidden-inputs.ts +8 -7
  157. package/src/mount.ts +2 -7
  158. package/src/notifier.ts +4 -6
  159. package/src/page/default-list-filters.ts +1 -0
  160. package/src/page/list.ts +18 -20
  161. package/src/page/mountable-with-fields.ts +3 -3
  162. package/src/page/mountable.ts +0 -1
  163. package/src/page/page.ts +2 -3
  164. package/src/page/props-parser.ts +1 -1
  165. package/src/page/sealious-list.ts +1 -1
  166. package/src/page/stateful-page.ts +6 -10
  167. package/src/register-external.ts +4 -4
  168. package/src/templates/form.ts +1 -2
  169. package/src/templates/jdd-component.ts +1 -1
  170. package/src/templates/jdd-editor.ts +2 -4
  171. package/src/templates/list.ts +0 -1
  172. package/src/templates/page.ts +1 -4
  173. package/src/templates/shared/collection-create-form.ts +5 -6
  174. package/src/templates/shared/collection-edit-form.ts +5 -6
  175. package/src/templates/shared/collection-list.ts +2 -2
  176. package/src/templates/shared/shared-crud-form-fields.ts +4 -9
  177. package/src/templates/templates.ts +5 -1
  178. package/src/test_utils/exec_async.ts +3 -4
  179. package/src/test_utils/test-on-real-app.ts +9 -11
  180. package/src/utils/browser-creator.js +0 -1
  181. package/src/utils/exec.ts +0 -1
  182. package/src/utils/input-wrapper.ts +1 -1
  183. package/src/utils/wrap-attributes.ts +1 -1
  184. package/src/utils/write-file.ts +1 -1
  185. package/.eslintrc.cjs +0 -44
package/src/page/list.ts CHANGED
@@ -48,7 +48,7 @@ function encodeSort(field: string, order: "asc" | "desc"): string {
48
48
 
49
49
  export abstract class ListPage<
50
50
  ItemType,
51
- F extends typeof BaseListPageFields
51
+ F extends typeof BaseListPageFields,
52
52
  > extends Page<F> {
53
53
  abstract getItems(
54
54
  ctx: Context,
@@ -126,7 +126,7 @@ export abstract class ListPage<
126
126
  values
127
127
  );
128
128
 
129
- return tempstream/* HTML */ `<div class="list-pagination">
129
+ return tempstream /* HTML */ `<div class="list-pagination">
130
130
  <div class="list-pagination__left">
131
131
  ${page > 1
132
132
  ? this.renderPageButton(ctx, 1, "Pierwsza strona")
@@ -141,18 +141,18 @@ export abstract class ListPage<
141
141
  onchange="if (this.value) Turbo.visit(this.value)"
142
142
  >
143
143
  ${Array.from(naturalNumbers(1, totalIems)).map(
144
- (n) => /* HTML */ `<option
145
- value="${UrlWithNewParams(
146
- ctx,
147
- //eslint-disable-next-line @typescript-eslint/consistent-type-assertions
148
- this.propsParser.overwriteProp(ctx, {
149
- page: n,
150
- } as Partial<Record<string, unknown>>)
151
- )}"
152
- ${page === n ? "selected" : ""}
153
- >
154
- ${n}
155
- </option>`
144
+ (n) =>
145
+ /* HTML */ `<option
146
+ value="${UrlWithNewParams(
147
+ ctx,
148
+ this.propsParser.overwriteProp(ctx, {
149
+ page: n,
150
+ } as Partial<Record<string, unknown>>)
151
+ )}"
152
+ ${page === n ? "selected" : ""}
153
+ >
154
+ ${n}
155
+ </option>`
156
156
  )}
157
157
  </select>
158
158
  </div>
@@ -171,7 +171,6 @@ export abstract class ListPage<
171
171
  return /* HTML */ `<a
172
172
  href="${UrlWithNewParams(
173
173
  ctx,
174
- //eslint-disable-next-line @typescript-eslint/consistent-type-assertions
175
174
  this.propsParser.overwriteProp(ctx, {
176
175
  page,
177
176
  } as Partial<Record<string, unknown>>)
@@ -219,13 +218,12 @@ export abstract class ListPage<
219
218
 
220
219
  async renderFilters(ctx: Context): Promise<FlatTemplatable> {
221
220
  const values = await this.extractRawValues(ctx);
222
- return tempstream/* HTML */ `<form method="GET">
221
+ return tempstream /* HTML */ `<form method="GET">
223
222
  ${makeHiddenInputs(ctx, this.fields, values, [
224
223
  "page",
225
224
  ...Object.values(this.filterFields).map((f) => f.name),
226
225
  ])}
227
226
  ${this.filterControls.map((control) => {
228
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
229
227
  return control.render(
230
228
  this.makeFormControlContext(
231
229
  ctx,
@@ -253,8 +251,8 @@ export abstract class ListPage<
253
251
  current_order === "asc" // cycles the sort order: null → "asc" → "desc" → null → ...
254
252
  ? "desc"
255
253
  : current_order === null
256
- ? "asc"
257
- : null;
254
+ ? "asc"
255
+ : null;
258
256
  return /* HTML */ `<th data-field="${field}">
259
257
  <a href="${this.makeSortLink(ctx, field, order)}"
260
258
  >${label}
@@ -272,7 +270,7 @@ export abstract class ListPage<
272
270
  ctx: Context,
273
271
  fields: { field: string; label?: string }[]
274
272
  ): FlatTemplatable {
275
- return tempstream/* HTML */ `<thead>
273
+ return tempstream /* HTML */ `<thead>
276
274
  <tr>
277
275
  ${fields.map(({ label, field }) =>
278
276
  this.renderHeading(ctx, field, label)
@@ -25,7 +25,7 @@ type ParsedValue<T extends FormField> = Resolved<
25
25
  >["parsed"];
26
26
 
27
27
  export abstract class MountableWithFields<
28
- F extends Fields = Fields
28
+ F extends Fields = Fields,
29
29
  > extends Mountable {
30
30
  fields: F;
31
31
  field_names_prefix = ""; // useful for multiform, where many forms are merged into one and field assignment is made using the prefix
@@ -116,7 +116,7 @@ export abstract class MountableWithFields<
116
116
  }
117
117
 
118
118
  public renderControls(fctx: FormControlContext): FlatTemplatable {
119
- return tempstream/* HTML */ `${this.controls.map((control) =>
119
+ return tempstream /* HTML */ `${this.controls.map((control) =>
120
120
  control.render(fctx)
121
121
  )}`;
122
122
  }
@@ -132,7 +132,7 @@ export abstract class MountableWithFields<
132
132
  _: Context,
133
133
  data: FormData<keyof Fields>
134
134
  ): FlatTemplatable {
135
- return tempstream/* HTML */ `<div class="form-messages">
135
+ return tempstream /* HTML */ `<div class="form-messages">
136
136
  ${data.messages.map(
137
137
  (message) =>
138
138
  `<div class="form-message form-message--${message.type}">${message.text}</div>`
@@ -3,7 +3,6 @@ import Router from "@koa/router";
3
3
  import { Context } from "koa";
4
4
 
5
5
  export abstract class Mountable {
6
- // eslint-disable-next-line @typescript-eslint/no-empty-function
7
6
  init(): void {}
8
7
  abstract mount(router: Router, path: string): void;
9
8
 
package/src/page/page.ts CHANGED
@@ -11,7 +11,7 @@ import {
11
11
  import { AllQueryParams, PagePropsParser } from "./props-parser.js";
12
12
 
13
13
  export abstract class Page<
14
- F extends Fields = Record<string, never>
14
+ F extends Fields = Record<string, never>,
15
15
  > extends MountableWithFields<F> {
16
16
  propsParser: PagePropsParser<Record<keyof Fields, unknown>> =
17
17
  new AllQueryParams();
@@ -23,7 +23,6 @@ export abstract class Page<
23
23
  });
24
24
  }
25
25
 
26
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
27
26
  async canAccess(_: Context) {
28
27
  return { canAccess: true, message: "" };
29
28
  }
@@ -32,7 +31,7 @@ export abstract class Page<
32
31
  _: Context,
33
32
  error: PageErrorMessage
34
33
  ): Promise<FlatTemplatable> {
35
- return tempstream/* HTML */ `<div>${error.message}</div>`;
34
+ return tempstream /* HTML */ `<div>${error.message}</div>`;
36
35
  }
37
36
 
38
37
  public abstract render(ctx: Context): Promise<FlatTemplatable>;
@@ -22,7 +22,7 @@ export abstract class PagePropsParser<PropsType> {
22
22
  }
23
23
 
24
24
  export class AllQueryParams<
25
- PropsType extends BasePageProps
25
+ PropsType extends BasePageProps,
26
26
  > extends PagePropsParser<PropsType> {
27
27
  decode(ctx: Context): Record<string, FormDataValue> {
28
28
  return ctx.query;
@@ -18,7 +18,7 @@ import { is, predicates } from "@sealcode/ts-predicates";
18
18
 
19
19
  export abstract class SealiousItemListPage<
20
20
  C extends Collection,
21
- F extends typeof BaseListPageFields
21
+ F extends typeof BaseListPageFields,
22
22
  > extends ListPage<CollectionItem<C>, F> {
23
23
  constructor(public collection: C) {
24
24
  super();
@@ -34,7 +34,7 @@ export type StateAndMetadata<State, Actions> =
34
34
 
35
35
  export type StatefulPageActionArgument<
36
36
  State extends Record<string, unknown>,
37
- Args extends unknown[] = unknown[]
37
+ Args extends unknown[] = unknown[],
38
38
  > = {
39
39
  ctx: Context;
40
40
  state: State;
@@ -45,19 +45,15 @@ export type StatefulPageActionArgument<
45
45
 
46
46
  export type StatefulPageAction<
47
47
  State extends Record<string, unknown>,
48
- Args extends unknown[] = unknown[]
48
+ Args extends unknown[] = unknown[],
49
49
  > = (obj: StatefulPageActionArgument<State, Args>) => State | Promise<State>;
50
50
 
51
- export type ExtractStatefulPageActionArgs<X> = X extends StatefulPageAction<
52
- any,
53
- infer Args
54
- >
55
- ? Args
56
- : never;
51
+ export type ExtractStatefulPageActionArgs<X> =
52
+ X extends StatefulPageAction<any, infer Args> ? Args : never;
57
53
 
58
54
  export abstract class StatefulPage<
59
55
  State extends Record<string, unknown>,
60
- Actions extends Record<string, StatefulPageAction<State>>
56
+ Actions extends Record<string, StatefulPageAction<State>>,
61
57
  > extends Mountable {
62
58
  abstract actions: Actions;
63
59
  abstract getInitialState(ctx: Context): State | Promise<State>;
@@ -104,7 +100,7 @@ export abstract class StatefulPage<
104
100
  state: State,
105
101
  content: Templatable
106
102
  ): Promise<Templatable> {
107
- return tempstream/* HTML */ `<form
103
+ return tempstream /* HTML */ `<form
108
104
  action="./"
109
105
  method="POST"
110
106
  enctype="multipart/form-data"
@@ -74,7 +74,7 @@ async function updatePackageJson(
74
74
 
75
75
  // Check if the path is already present
76
76
  if (existingPaths.includes(pathToAdd)) {
77
- console.log(`${type} already contains: ${pathToAdd}`);
77
+ console.warn(`${type} already contains: ${pathToAdd}`);
78
78
  return;
79
79
  }
80
80
 
@@ -88,11 +88,11 @@ async function updatePackageJson(
88
88
  );
89
89
 
90
90
  await fs.writeFile(packageJsonPath, updatedContent);
91
- console.log(`Added ${pathToAdd} to ${type} in ${packageJsonPath}`);
91
+ console.info(`Added ${pathToAdd} to ${type} in ${packageJsonPath}`);
92
92
  }
93
93
 
94
94
  export async function registerExternalControllers(
95
- args: Record<string, string | boolean>
95
+ _args: Record<string, string | boolean>
96
96
  ): Promise<void> {
97
97
  // Extract positional arguments from process.argv since yargs doesn't handle them for these commands
98
98
  const moduleName = process.argv.at(3);
@@ -120,7 +120,7 @@ export async function registerExternalControllers(
120
120
  }
121
121
 
122
122
  export async function registerExternalStyles(
123
- args: Record<string, string | boolean>
123
+ _args: Record<string, string | boolean>
124
124
  ): Promise<void> {
125
125
  // Extract positional arguments from process.argv since yargs doesn't handle them for these commands
126
126
  const moduleName = process.argv.at(3);
@@ -43,8 +43,7 @@ const defaults = {
43
43
 
44
44
  export async function formTemplate(
45
45
  action_name: string,
46
- newfilefullpath: string,
47
- _params: Partial<typeof defaults> & { success_message: string } = defaults
46
+ _params: Partial<typeof defaults> = defaults
48
47
  ): Promise<string> {
49
48
  const params = { ...defaults, ..._params };
50
49
  const content = `import type { Context } from "koa";
@@ -1,6 +1,6 @@
1
1
  import { toKebabCase, toPascalCase } from "js-convert-case";
2
2
 
3
- export function jddComponentTemplate(component_name: string) {
3
+ export async function jddComponentTemplate(component_name: string) {
4
4
  return `import { TempstreamJSX } from "tempstream";
5
5
  import type { ComponentToHTMLArgs } from "@sealcode/jdd";
6
6
  import { Component, ComponentArguments } from "@sealcode/jdd";
@@ -12,9 +12,7 @@ export async function jddEditorTemplate(actionName: string) {
12
12
  name: "collection",
13
13
  message:
14
14
  "Which sealious collection do you like to add CRUD forms for?",
15
- choices: (
16
- await listCollections()
17
- ).map((collection) => ({
15
+ choices: (await listCollections()).map((collection) => ({
18
16
  title: collection,
19
17
  value: collection,
20
18
  })),
@@ -30,7 +28,7 @@ export async function jddEditorTemplate(actionName: string) {
30
28
  let field_name = "";
31
29
  if (jdd_fields.length == 1) {
32
30
  field_name = jdd_fields[0].name;
33
- console.log(
31
+ console.info(
34
32
  `Only one field of type JDD found: ${field_name}, so skipping the question...`
35
33
  );
36
34
  } else if (jdd_fields.length > 1) {
@@ -1,4 +1,3 @@
1
- import _locreq from "locreq";
2
1
  import prompts from "prompts";
3
2
  import { listCollections } from "../utils/list-collections.js";
4
3
  import { formatWithPrettier } from "../utils/prettier.js";
@@ -1,7 +1,4 @@
1
- export async function pageTemplate(
2
- action_name: string,
3
- newfilefullpath: string
4
- ): Promise<string> {
1
+ export async function pageTemplate(action_name: string): Promise<string> {
5
2
  return `import type { Context } from "koa";
6
3
  import { TempstreamJSX } from "tempstream";
7
4
  import { Page } from "@sealcode/sealgen";
@@ -1,7 +1,6 @@
1
1
  import { toKebabCase, toPascalCase } from "js-convert-case";
2
2
  import { formTemplate } from "../form.js";
3
3
 
4
- import _locreq from "locreq";
5
4
  import extract_fields_from_collection from "../../utils/extract-fields-from-collection.js";
6
5
  import { wrapAttribute } from "../../utils/wrap-attributes.js";
7
6
 
@@ -11,12 +10,11 @@ export async function createItemFormTemplate(
11
10
  collection_name: string,
12
11
  list_action: string
13
12
  ): Promise<string> {
14
- const collection_fields = await extract_fields_from_collection(
15
- collection_name
16
- );
13
+ const collection_fields =
14
+ await extract_fields_from_collection(collection_name);
17
15
  const formFieldsVar = `${toPascalCase(collection_name)}FormFields`;
18
16
 
19
- return formTemplate(create_action_name, newfilefullpath, {
17
+ return formTemplate(create_action_name, {
20
18
  success_message: "Created!",
21
19
  postimport: `import {${formFieldsVar}, get${toPascalCase(
22
20
  collection_name
@@ -65,7 +63,8 @@ export async function createItemFormTemplate(
65
63
  .join(",\n")}
66
64
  });
67
65
 
68
- for(const field of Object.values(${formFieldsVar})){
66
+ for(const field of Object.values(${formFieldsVar})){
67
+ // eslint-disable-next-line no-await-in-loop
69
68
  await field.postSealiousCreate(ctx, created, formData)
70
69
  }
71
70
  }
@@ -1,7 +1,6 @@
1
1
  import { toKebabCase, toPascalCase } from "js-convert-case";
2
2
  import { formTemplate } from "../form.js";
3
3
 
4
- import _locreq from "locreq";
5
4
  import extract_fields_from_collection from "../../utils/extract-fields-from-collection.js";
6
5
  import { wrapAttribute } from "../../utils/wrap-attributes.js";
7
6
 
@@ -11,13 +10,12 @@ export async function editItemFormTemplate(
11
10
  collection_name: string,
12
11
  list_action: string
13
12
  ): Promise<string> {
14
- const collection_fields = await extract_fields_from_collection(
15
- collection_name
16
- );
13
+ const collection_fields =
14
+ await extract_fields_from_collection(collection_name);
17
15
  const formFieldsVar = `${toPascalCase(collection_name)}FormFields`;
18
16
  const collectionVar = `${toPascalCase(collection_name)}`;
19
17
 
20
- return formTemplate(edit_action_name, newfilefullpath, {
18
+ return formTemplate(edit_action_name, {
21
19
  success_message: "Changes saved!",
22
20
  postimport: `import {${formFieldsVar}, get${toPascalCase(
23
21
  collection_name
@@ -80,7 +78,8 @@ export async function editItemFormTemplate(
80
78
  await item.save(ctx.$context);
81
79
 
82
80
  for(const field of Object.values(${formFieldsVar})){
83
- await field.postSealiousEdit(ctx, item, formData)
81
+ // eslint-disable-next-line no-await-in-loop
82
+ await field.postSealiousEdit(ctx, item, formData)
84
83
  }
85
84
  }
86
85
  `,
@@ -132,7 +132,7 @@ ${field_import_string}
132
132
  export const actionName = "${action_name}";
133
133
 
134
134
  const filterFields:{
135
- field: keyof (typeof HasAllFields)["fields"];
135
+ field: keyof (typeof ${uppercase_collection})["fields"];
136
136
  render?: ListFilterRender;
137
137
  prepareValue?: (filter_value: unknown) => unknown; // set this function to change what filter value is passed to Sealious
138
138
  }[] = [
@@ -207,7 +207,7 @@ export default new (class ${action_name}Page extends SealiousItemListPage<
207
207
  ctx: Context,
208
208
  fields: { field: string; label?: string }[]
209
209
  ): FlatTemplatable {
210
- return tempstream/* HTML */ \`<thead>
210
+ return tempstream /* HTML */ \`<thead>
211
211
  <tr>
212
212
  \${fields.map(({ label, field }) => this.renderHeading(ctx, field, label))}
213
213
  <th>Actions</th>
@@ -1,20 +1,15 @@
1
1
  import { toPascalCase } from "js-convert-case";
2
- import _locreq from "locreq";
3
2
  import extract_fields_from_collection from "../../utils/extract-fields-from-collection.js";
4
3
  import { formatWithPrettier } from "../../utils/prettier.js";
5
4
  import { wrapAttribute } from "../../utils/wrap-attributes.js";
6
5
 
7
- export async function sharedCrudFormFields(
8
- collection_name: string,
9
- newfilefullpath: string
10
- ) {
11
- const collection_fields = await extract_fields_from_collection(
12
- collection_name
13
- );
6
+ export async function sharedCrudFormFields(collection_name: string) {
7
+ const collection_fields =
8
+ await extract_fields_from_collection(collection_name);
14
9
 
15
10
  const uppercase_collection = toPascalCase(collection_name);
16
11
 
17
- const result = `import { Controls, Fields } from "@sealcode/sealgen";
12
+ const result = `import { type Controls, Fields } from "@sealcode/sealgen";
18
13
  import { ${uppercase_collection} } from "src/back/collections/collections.js";
19
14
  ${Array.from(
20
15
  new Set(
@@ -9,7 +9,11 @@ import { redirectTemplate } from "./redirect.js";
9
9
  import { statefulPageTemplate } from "./stateful-page.js";
10
10
  import { jddEditorTemplate } from "./jdd-editor.js";
11
11
 
12
- export const Templates = {
12
+ export const Templates: Record<
13
+ string,
14
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
15
+ (action: string, params: any) => Promise<string>
16
+ > = {
13
17
  page: pageTemplate,
14
18
  form: formTemplate,
15
19
  list: listTemplate,
@@ -1,18 +1,17 @@
1
- /* eslint-disable @typescript-eslint/restrict-template-expressions */
2
1
  import { exec } from "child_process";
3
2
 
4
3
  export const execAsync = (cmd: string) => {
5
4
  return new Promise<void>((resolve, reject) => {
6
5
  const process = exec(cmd);
7
6
 
8
- console.log("EXECUTING", cmd);
7
+ console.info("EXECUTING", cmd);
9
8
 
10
9
  process?.stdout?.on("data", (data) => {
11
- console.log(`stdout: ${data}`);
10
+ console.info(`stdout: ${data}`);
12
11
  });
13
12
 
14
13
  process?.stderr?.on("data", (data) => {
15
- console.log(`stdout: ${data}`);
14
+ console.info(`stdout: ${data}`);
16
15
  });
17
16
 
18
17
  process.on("exit", (code) => {
@@ -33,18 +33,18 @@ export class RealAppTest {
33
33
  const timestamp = Date.now();
34
34
  test_app.app_path = `/tmp/sealious-minimal-${timestamp}`;
35
35
  test_app.container_name = `sealgen-test-mongo-${timestamp}`;
36
- console.log("\tcloning sealious-minimal...");
36
+ console.info("\tcloning sealious-minimal...");
37
37
  await execAsync(
38
38
  `git clone ${sealious_minimal_url} ${test_app.app_path} && cd ${test_app.app_path} && git checkout ${sealious_minimal_commit}`
39
39
  );
40
- console.log("\tinstalling dependencies and sealgen...");
40
+ console.info("\tinstalling dependencies and sealgen...");
41
41
  await execAsync(
42
42
  `cd ${
43
43
  test_app.app_path
44
44
  } && npm ci rm -rf node_modules/@sealcode/sealgen && ln -s $OLDPWD node_modules/@sealcode/sealgen && ${callSealgenBin()} make-env`
45
45
  );
46
46
 
47
- console.log(
47
+ console.info(
48
48
  "\tstarting the database...(if timeouts here, run 'docker pull mongo:4.4-bionic' to solve)"
49
49
  );
50
50
  await test_app.runSealgenCommand("build");
@@ -63,7 +63,7 @@ export class RealAppTest {
63
63
  SEALIOUS_PORT: this.app_port.toString(),
64
64
  };
65
65
  const node_args = [`${this.app_path}/dist/back/index.js`];
66
- console.log(
66
+ console.info(
67
67
  "EXECUTING APP",
68
68
  `${Object.entries(env)
69
69
  .map(([key, value]) => `${key}=${value}`)
@@ -73,9 +73,9 @@ export class RealAppTest {
73
73
  env,
74
74
  });
75
75
  app_start.stdout.on("data", (data) =>
76
- console.log("APP OUTPUT:", data.toString())
76
+ console.info("APP OUTPUT:", data.toString())
77
77
  );
78
- app_start.stderr.on("data", (data) => console.log(data.toString()));
78
+ app_start.stderr.on("data", (data) => console.info(data.toString()));
79
79
  app_start.on("exit", (code) => {
80
80
  this.emitter.emit("exit", code);
81
81
  this.emitter.emit("process_error");
@@ -88,7 +88,7 @@ export class RealAppTest {
88
88
  output: "silent",
89
89
  timeout: 6000,
90
90
  });
91
- console.log(
91
+ console.info(
92
92
  chalk.yellow(
93
93
  `App is listening on http://localhost:${this.app_port}`
94
94
  )
@@ -98,7 +98,7 @@ export class RealAppTest {
98
98
  async close() {
99
99
  try {
100
100
  if (this.node_pid != 0) await execAsync(`kill -9 ${this.node_pid}`);
101
- } catch (error) {
101
+ } catch (_error) {
102
102
  throw new Error(
103
103
  "node process exited unexpectedly, please inspect the output"
104
104
  );
@@ -174,14 +174,12 @@ export class RealAppTest {
174
174
  const status = ret.status;
175
175
  const response = await ret.text();
176
176
 
177
- console.debug("request done!");
178
- console.debug({ response });
179
177
  return { status, response };
180
178
  });
181
179
  }
182
180
 
183
181
  async addFile(target_path: string, content: string) {
184
- console.log(
182
+ console.info(
185
183
  chalk.yellow("Inserting file at path"),
186
184
  chalk.green(target_path),
187
185
  "with content\n",
@@ -2,7 +2,6 @@ import { firefox } from "playwright";
2
2
 
3
3
  let browser_promise = null;
4
4
 
5
- // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
6
5
  export async function getBrowser() {
7
6
  if (!browser_promise) browser_promise = firefox.launch();
8
7
  // eslint-disable-next-line @typescript-eslint/no-unsafe-return
package/src/utils/exec.ts CHANGED
@@ -1,4 +1,3 @@
1
- /* eslint-disable no-console */
2
1
  import { spawn } from "child_process";
3
2
 
4
3
  export async function exec(
@@ -13,7 +13,7 @@ export async function inputWrapper(
13
13
  modifiers: string[],
14
14
  input: FlatTemplatable
15
15
  ): Promise<string> {
16
- return tempstream/* HTML */ `<div
16
+ return tempstream /* HTML */ `<div
17
17
  class="form-input form-input--type-${type} form-input__wrapper ${getModifierClasses(
18
18
  modifiers
19
19
  )}"
@@ -1,6 +1,6 @@
1
1
  export function needsQuotes(str: string) {
2
2
  try {
3
- // eslint-disable-next-line @typescript-eslint/no-implied-eval
3
+ // eslint-disable-next-line @typescript-eslint/no-implied-eval
4
4
  new Function(`var obj = { ${str}: 1 };`);
5
5
  return false;
6
6
  } catch {
@@ -4,5 +4,5 @@ import { resolve } from "path";
4
4
  export async function writeFile(path: string, content: string) {
5
5
  await fs.mkdir(resolve(path, "../"), { recursive: true });
6
6
  await fs.writeFile(path, content);
7
- console.log(`${path} created`);
7
+ console.info(`${path} created`);
8
8
  }
package/.eslintrc.cjs DELETED
@@ -1,44 +0,0 @@
1
- module.exports = {
2
- env: { node: true },
3
- parser: "@typescript-eslint/parser",
4
- plugins: ["@typescript-eslint", "prettier"],
5
- extends: [
6
- "eslint:recommended",
7
- "plugin:@typescript-eslint/recommended",
8
- "plugin:@typescript-eslint/recommended-requiring-type-checking",
9
- "plugin:prettier/recommended",
10
- ],
11
- ignorePatterns: [".eslintrc.js", "src/**/*.test.ts", "@types/*"],
12
- parserOptions: {
13
- sourceType: "module",
14
- ecmaFeatures: {
15
- modules: true,
16
- },
17
- project: ["./tsconfig.json"],
18
- },
19
- rules: {
20
- "@typescript-eslint/require-await": 0,
21
- "no-await-in-loop": 2,
22
- "@typescript-eslint/no-unused-vars": [
23
- "warn",
24
- { args: "none", varsIgnorePattern: "^_" },
25
- ],
26
- "@typescript-eslint/no-this-alias": 0,
27
- "@typescript-eslint/no-empty-function": 0,
28
- "@typescript-eslint/no-explicit-any": 0,
29
- },
30
- settings: { jsdoc: { mode: "typescript" } },
31
- overrides: [
32
- {
33
- files: ["*.subtest.ts", "*.test.ts"],
34
- rules: {
35
- "@typescript-eslint/no-unsafe-member-access": 0,
36
- "prefer-const": 0,
37
- "@typescript-eslint/no-unsafe-call": 0,
38
- "@typescript-eslint/no-unsafe-return": 0,
39
- "@typescript-eslint/no-unsafe-assignment": 0,
40
- "no-await-in-loop": 1, // sometimes it's easier to debug when requests run sequentially
41
- },
42
- },
43
- ],
44
- };