@sealcode/sealgen 0.12.0 → 0.12.2

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 (266) hide show
  1. package/package.json +2 -2
  2. package/.madgerc +0 -7
  3. package/coverage/.tmp/coverage-15.json +0 -1
  4. package/coverage/.tmp/coverage-16.json +0 -1
  5. package/coverage/.tmp/coverage-17.json +0 -1
  6. package/coverage/.tmp/coverage-18.json +0 -1
  7. package/coverage/.tmp/coverage-19.json +0 -1
  8. package/coverage/.tmp/coverage-20.json +0 -1
  9. package/coverage/.tmp/coverage-21.json +0 -1
  10. package/coverage/.tmp/coverage-22.json +0 -1
  11. package/coverage/.tmp/coverage-23.json +0 -1
  12. package/coverage/.tmp/coverage-24.json +0 -1
  13. package/coverage/.tmp/coverage-25.json +0 -1
  14. package/coverage/.tmp/coverage-26.json +0 -1
  15. package/lib/add-collection.js +0 -24
  16. package/lib/add-jdd-component.js +0 -27
  17. package/lib/add-route.js +0 -65
  18. package/lib/add-route.test.js +0 -60
  19. package/lib/build.js +0 -187
  20. package/lib/cli.js +0 -35
  21. package/lib/components/components.js +0 -3
  22. package/lib/components/tabs.js +0 -88
  23. package/lib/components/toggle-modal.js +0 -46
  24. package/lib/example.test.js +0 -5
  25. package/lib/find-css-includes.js +0 -23
  26. package/lib/forms/controls/array.js +0 -140
  27. package/lib/forms/controls/autocomplete.js +0 -23
  28. package/lib/forms/controls/big-radio-group.js +0 -34
  29. package/lib/forms/controls/checkbox-group.js +0 -29
  30. package/lib/forms/controls/checkbox.js +0 -24
  31. package/lib/forms/controls/checkboxed-list-input.js +0 -35
  32. package/lib/forms/controls/collapsible-checkbox-group.js +0 -13
  33. package/lib/forms/controls/collapsible-field-group.js +0 -78
  34. package/lib/forms/controls/controls.js +0 -31
  35. package/lib/forms/controls/derived-frame.js +0 -52
  36. package/lib/forms/controls/derived.js +0 -77
  37. package/lib/forms/controls/dropdown.js +0 -55
  38. package/lib/forms/controls/editable-collection-subset.js +0 -68
  39. package/lib/forms/controls/field-group.js +0 -53
  40. package/lib/forms/controls/file.js +0 -35
  41. package/lib/forms/controls/form-control.js +0 -14
  42. package/lib/forms/controls/form-field-control.js +0 -9
  43. package/lib/forms/controls/form-header.js +0 -14
  44. package/lib/forms/controls/form-paragraph.js +0 -12
  45. package/lib/forms/controls/frame.js +0 -25
  46. package/lib/forms/controls/hidden-input.js +0 -14
  47. package/lib/forms/controls/html.js +0 -23
  48. package/lib/forms/controls/multiple-files.js +0 -160
  49. package/lib/forms/controls/multiple-photos.js +0 -33
  50. package/lib/forms/controls/number.js +0 -25
  51. package/lib/forms/controls/photo.js +0 -57
  52. package/lib/forms/controls/radio.js +0 -25
  53. package/lib/forms/controls/reverse-single-reference.js +0 -47
  54. package/lib/forms/controls/simple-input.js +0 -78
  55. package/lib/forms/controls/textarea.js +0 -33
  56. package/lib/forms/controls/tickable.js +0 -75
  57. package/lib/forms/fields/boolean.js +0 -51
  58. package/lib/forms/fields/boolean.test.js +0 -32
  59. package/lib/forms/fields/checkboxed-list.js +0 -40
  60. package/lib/forms/fields/collection-field.js +0 -29
  61. package/lib/forms/fields/email.js +0 -11
  62. package/lib/forms/fields/email.test.js +0 -20
  63. package/lib/forms/fields/enum-multiple.js +0 -47
  64. package/lib/forms/fields/enum-multiple.test.js +0 -27
  65. package/lib/forms/fields/enum.js +0 -39
  66. package/lib/forms/fields/enum.test.js +0 -21
  67. package/lib/forms/fields/existing-sealious-value.js +0 -16
  68. package/lib/forms/fields/field.js +0 -81
  69. package/lib/forms/fields/file.js +0 -53
  70. package/lib/forms/fields/multiple-files.js +0 -15
  71. package/lib/forms/fields/number.js +0 -45
  72. package/lib/forms/fields/number.test.js +0 -30
  73. package/lib/forms/fields/pick-from-list.js +0 -31
  74. package/lib/forms/fields/pick-from-list.test.js +0 -17
  75. package/lib/forms/fields/proxy-field.js +0 -20
  76. package/lib/forms/fields/regexp.js +0 -40
  77. package/lib/forms/fields/regexp.test.js +0 -21
  78. package/lib/forms/fields/reverse-single-reference.js +0 -14
  79. package/lib/forms/fields/simple-form-field.js +0 -20
  80. package/lib/forms/fields/structured-array.js +0 -18
  81. package/lib/forms/form.js +0 -176
  82. package/lib/forms/form.test.js +0 -1
  83. package/lib/forms/multiform.js +0 -174
  84. package/lib/forms/multiform.test.js +0 -426
  85. package/lib/generate-collections.js +0 -52
  86. package/lib/generate-components.js +0 -33
  87. package/lib/generate-routes.js +0 -75
  88. package/lib/index.js +0 -17
  89. package/lib/make-env.js +0 -14
  90. package/lib/make-hidden-inputs.js +0 -14
  91. package/lib/mount.js +0 -70
  92. package/lib/notifier.js +0 -19
  93. package/lib/page/access-control.js +0 -16
  94. package/lib/page/default-list-filters.js +0 -40
  95. package/lib/page/list.js +0 -183
  96. package/lib/page/mountable-with-fields.js +0 -85
  97. package/lib/page/mountable.js +0 -5
  98. package/lib/page/page.js +0 -26
  99. package/lib/page/props-parser.js +0 -23
  100. package/lib/page/sealious-list.js +0 -59
  101. package/lib/page/stateful-page.js +0 -97
  102. package/lib/remove-named-imports.js +0 -47
  103. package/lib/run.js +0 -2
  104. package/lib/sanitize.js +0 -10
  105. package/lib/src/add-collection.js +0 -24
  106. package/lib/src/add-jdd-component.js +0 -27
  107. package/lib/src/add-route.js +0 -65
  108. package/lib/src/add-route.test.js +0 -72
  109. package/lib/src/build.js +0 -142
  110. package/lib/src/cli.js +0 -37
  111. package/lib/src/components/components.js +0 -3
  112. package/lib/src/components/tabs.js +0 -88
  113. package/lib/src/components/toggle-modal.js +0 -46
  114. package/lib/src/example.test.js +0 -5
  115. package/lib/src/find-css-includes.js +0 -23
  116. package/lib/src/forms/controls/array.js +0 -141
  117. package/lib/src/forms/controls/autocomplete.js +0 -23
  118. package/lib/src/forms/controls/big-radio-group.js +0 -34
  119. package/lib/src/forms/controls/checkbox-group.js +0 -30
  120. package/lib/src/forms/controls/checkbox.js +0 -24
  121. package/lib/src/forms/controls/checkboxed-list-input.js +0 -35
  122. package/lib/src/forms/controls/collapsible-checkbox-group.js +0 -13
  123. package/lib/src/forms/controls/collapsible-field-group.js +0 -78
  124. package/lib/src/forms/controls/controls.js +0 -31
  125. package/lib/src/forms/controls/derived-frame.js +0 -52
  126. package/lib/src/forms/controls/derived.js +0 -77
  127. package/lib/src/forms/controls/dropdown.js +0 -55
  128. package/lib/src/forms/controls/editable-collection-subset.js +0 -68
  129. package/lib/src/forms/controls/field-group.js +0 -53
  130. package/lib/src/forms/controls/file.js +0 -35
  131. package/lib/src/forms/controls/form-control.js +0 -14
  132. package/lib/src/forms/controls/form-field-control.js +0 -9
  133. package/lib/src/forms/controls/form-header.js +0 -14
  134. package/lib/src/forms/controls/form-paragraph.js +0 -12
  135. package/lib/src/forms/controls/frame.js +0 -25
  136. package/lib/src/forms/controls/hidden-input.js +0 -14
  137. package/lib/src/forms/controls/html.js +0 -23
  138. package/lib/src/forms/controls/multiple-files.js +0 -160
  139. package/lib/src/forms/controls/multiple-photos.js +0 -33
  140. package/lib/src/forms/controls/number.js +0 -25
  141. package/lib/src/forms/controls/photo.js +0 -57
  142. package/lib/src/forms/controls/radio.js +0 -25
  143. package/lib/src/forms/controls/reverse-single-reference.js +0 -47
  144. package/lib/src/forms/controls/simple-input.js +0 -78
  145. package/lib/src/forms/controls/textarea.js +0 -33
  146. package/lib/src/forms/controls/tickable.js +0 -75
  147. package/lib/src/forms/fields/boolean.js +0 -51
  148. package/lib/src/forms/fields/boolean.test.js +0 -33
  149. package/lib/src/forms/fields/checkboxed-list.js +0 -40
  150. package/lib/src/forms/fields/collection-field.js +0 -29
  151. package/lib/src/forms/fields/email.js +0 -11
  152. package/lib/src/forms/fields/email.test.js +0 -20
  153. package/lib/src/forms/fields/enum-multiple.js +0 -47
  154. package/lib/src/forms/fields/enum-multiple.test.js +0 -27
  155. package/lib/src/forms/fields/enum.js +0 -39
  156. package/lib/src/forms/fields/enum.test.js +0 -21
  157. package/lib/src/forms/fields/existing-sealious-value.js +0 -16
  158. package/lib/src/forms/fields/field.js +0 -66
  159. package/lib/src/forms/fields/fields.js +0 -16
  160. package/lib/src/forms/fields/file.js +0 -53
  161. package/lib/src/forms/fields/multiple-files.js +0 -15
  162. package/lib/src/forms/fields/number.js +0 -45
  163. package/lib/src/forms/fields/number.test.js +0 -31
  164. package/lib/src/forms/fields/pick-from-list.js +0 -31
  165. package/lib/src/forms/fields/pick-from-list.test.js +0 -17
  166. package/lib/src/forms/fields/proxy-field.js +0 -20
  167. package/lib/src/forms/fields/regexp.js +0 -40
  168. package/lib/src/forms/fields/regexp.test.js +0 -21
  169. package/lib/src/forms/fields/reverse-single-reference.js +0 -14
  170. package/lib/src/forms/fields/simple-form-field.js +0 -19
  171. package/lib/src/forms/fields/structured-array.js +0 -18
  172. package/lib/src/forms/form-types.js +0 -2
  173. package/lib/src/forms/form.js +0 -176
  174. package/lib/src/forms/form.test.js +0 -271
  175. package/lib/src/forms/multiform.js +0 -174
  176. package/lib/src/forms/multiform.test.js +0 -430
  177. package/lib/src/generate-collections.js +0 -52
  178. package/lib/src/generate-components.js +0 -33
  179. package/lib/src/generate-routes.js +0 -75
  180. package/lib/src/hehe.test.js +0 -7
  181. package/lib/src/index.js +0 -19
  182. package/lib/src/make-env.js +0 -14
  183. package/lib/src/make-hidden-inputs.js +0 -14
  184. package/lib/src/mount.js +0 -70
  185. package/lib/src/notifier.js +0 -19
  186. package/lib/src/page/access-control.js +0 -16
  187. package/lib/src/page/default-list-filters.js +0 -40
  188. package/lib/src/page/list.js +0 -184
  189. package/lib/src/page/mountable-with-fields.js +0 -85
  190. package/lib/src/page/mountable.js +0 -5
  191. package/lib/src/page/page.js +0 -26
  192. package/lib/src/page/props-parser.js +0 -23
  193. package/lib/src/page/sealious-list.js +0 -59
  194. package/lib/src/page/stateful-page.js +0 -97
  195. package/lib/src/run.js +0 -2
  196. package/lib/src/sample-index.js +0 -3
  197. package/lib/src/sample-lib.js +0 -6
  198. package/lib/src/sanitize.js +0 -10
  199. package/lib/src/templates/collection.js +0 -12
  200. package/lib/src/templates/form.js +0 -57
  201. package/lib/src/templates/jdd-component.js +0 -39
  202. package/lib/src/templates/list.js +0 -139
  203. package/lib/src/templates/long-running-process.js +0 -60
  204. package/lib/src/templates/multiform.js +0 -55
  205. package/lib/src/templates/page.js +0 -23
  206. package/lib/src/templates/post.js +0 -22
  207. package/lib/src/templates/redirect.js +0 -23
  208. package/lib/src/templates/route-test.js +0 -54
  209. package/lib/src/templates/stateful-page.js +0 -66
  210. package/lib/src/templates/templates.js +0 -21
  211. package/lib/src/test_utils/locator_is_visible.js +0 -11
  212. package/lib/src/utils/assert-throws.js +0 -17
  213. package/lib/src/utils/base64.js +0 -7
  214. package/lib/src/utils/browser-creator.js +0 -10
  215. package/lib/src/utils/escape-url-params.js +0 -14
  216. package/lib/src/utils/exec.js +0 -22
  217. package/lib/src/utils/extract-fields-from-collection.js +0 -26
  218. package/lib/src/utils/format-external-url.js +0 -11
  219. package/lib/src/utils/import-path.js +0 -16
  220. package/lib/src/utils/input-wrapper.js +0 -15
  221. package/lib/src/utils/list-collections.js +0 -13
  222. package/lib/src/utils/make-slug.js +0 -6
  223. package/lib/src/utils/natural-numbers.js +0 -6
  224. package/lib/src/utils/prettier.js +0 -10
  225. package/lib/src/utils/question.js +0 -19
  226. package/lib/src/utils/render-attributes.js +0 -19
  227. package/lib/src/utils/sleep.js +0 -4
  228. package/lib/src/utils/translate.js +0 -6
  229. package/lib/src/utils/url-with-new-params.js +0 -5
  230. package/lib/src/utils/utils.js +0 -16
  231. package/lib/src/utils/walk.js +0 -23
  232. package/lib/src/vitest.config.js +0 -20
  233. package/lib/templates/collection.js +0 -12
  234. package/lib/templates/form.js +0 -57
  235. package/lib/templates/jdd-component.js +0 -39
  236. package/lib/templates/list.js +0 -139
  237. package/lib/templates/long-running-process.js +0 -60
  238. package/lib/templates/multiform.js +0 -55
  239. package/lib/templates/page.js +0 -23
  240. package/lib/templates/post.js +0 -22
  241. package/lib/templates/redirect.js +0 -23
  242. package/lib/templates/route-test.js +0 -54
  243. package/lib/templates/stateful-page.js +0 -66
  244. package/lib/templates/templates.js +0 -21
  245. package/lib/test_utils/locator_is_visible.js +0 -11
  246. package/lib/utils/assert-throws.js +0 -17
  247. package/lib/utils/base64.js +0 -7
  248. package/lib/utils/browser-creator.js +0 -10
  249. package/lib/utils/escape-url-params.js +0 -14
  250. package/lib/utils/exec.js +0 -22
  251. package/lib/utils/extract-fields-from-collection.js +0 -26
  252. package/lib/utils/format-external-url.js +0 -11
  253. package/lib/utils/import-path.js +0 -16
  254. package/lib/utils/input-wrapper.js +0 -15
  255. package/lib/utils/list-collections.js +0 -13
  256. package/lib/utils/make-slug.js +0 -6
  257. package/lib/utils/natural-numbers.js +0 -6
  258. package/lib/utils/prettier.js +0 -10
  259. package/lib/utils/question.js +0 -19
  260. package/lib/utils/render-attributes.js +0 -19
  261. package/lib/utils/sleep.js +0 -4
  262. package/lib/utils/translate.js +0 -6
  263. package/lib/utils/url-with-new-params.js +0 -5
  264. package/lib/utils/utils.js +0 -16
  265. package/lib/utils/walk.js +0 -23
  266. package/lib/vitest.config.js +0 -22
@@ -1,75 +0,0 @@
1
- import { attribute } from "../../sanitize.js";
2
- import { getRequiredClass, inputWrapper } from "../../utils/input-wrapper.js";
3
- import { FormFieldControl } from "./form-field-control.js";
4
- export class Tickable extends FormFieldControl {
5
- constructor(field, options = {}) {
6
- super([field]);
7
- this.field = field;
8
- this.options = options;
9
- }
10
- makeInputID(ctx, data, value) {
11
- const value_attr = this.getValueAttribute(ctx, data, value);
12
- return (this.options.id ||
13
- this.field.name + (value_attr ? "--" + value_attr : ""));
14
- }
15
- getWrapperClasses(ctx, data, value) {
16
- return [
17
- this.makeInputID(ctx, data, value),
18
- this.type,
19
- this.field.name.replaceAll(/\W/g, "-"),
20
- getRequiredClass(this.field.required),
21
- ...(this.isChecked(ctx, data, value) ? ["checked"] : []),
22
- ];
23
- }
24
- async render(fctx) {
25
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
26
- const { parsed, valid, message } = await this.field.getValue(fctx.ctx, fctx.data);
27
- const value = this.getValueAttribute(fctx.ctx, fctx.data, parsed);
28
- const id = this.makeInputID(fctx.ctx, fctx.data, parsed);
29
- const label = this.options.label != undefined
30
- ? this.options.label
31
- : this.field.name;
32
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
33
- const readonly = this.options.readonly || false;
34
- const required = this.field.required;
35
- return inputWrapper(this.getWrapperClasses(fctx.ctx, fctx.data, parsed),
36
- /* HTML */ `
37
- <input
38
- id="${id}"
39
- type="${this.type}"
40
- name="${fctx.field_name_prefix}${this.options.name ||
41
- this.field.name}"
42
- ${value ? `value="${attribute(value)}"` : ""}
43
- ${fctx.form_id ? `form="${fctx.form_id}"` : ""}
44
- ${this.isChecked(fctx.ctx, fctx.data, parsed)
45
- ? "checked"
46
- : ""}
47
- ${readonly ? "readonly" : ""}
48
- ${required ? "required" : ""}
49
- autocomplete="off"
50
- onchange="this.closest('.form-container').querySelectorAll('.form-input__wrapper--${this
51
- .field
52
- .name}').forEach(e=>e.setAttribute('data-checked','false'));
53
- this.closest('.form-input__wrapper').setAttribute('data-checked',this.checked);"
54
- />
55
-
56
- <label for="${id}">${label}</label>
57
- <script>
58
- (function () {
59
- let wrapper = document.currentScript.closest(
60
- ".form-input__wrapper"
61
- );
62
- wrapper.setAttribute(
63
- "data-checked",
64
- wrapper.querySelector("input").checked.toString()
65
- );
66
- })();
67
- </script>
68
-
69
- ${~valid && !this.options.hide_errors && fctx.validate
70
- ? `<div class="input__error">${message}</div>`
71
- : ""}
72
- `);
73
- }
74
- }
75
- //# sourceMappingURL=tickable.js.map
@@ -1,51 +0,0 @@
1
- import { is, predicates } from "@sealcode/ts-predicates";
2
- import { FormField } from "./field.js";
3
- const truthy = ["true", "on", "yes", "1"];
4
- const falsy = ["false", "off", "no", "0"];
5
- export class Boolean extends FormField {
6
- constructor(required, error_message = "") {
7
- super(required);
8
- this.error_message = error_message;
9
- this.predicate = predicates.boolean;
10
- }
11
- async isValueValid(_, value) {
12
- if (this.required && !value) {
13
- return { valid: false, message: this.error_message };
14
- }
15
- return { valid: true, message: "" };
16
- }
17
- async parse(_, value) {
18
- if (is(value, predicates.boolean)) {
19
- return { parsable: true, parsed_value: value, error: null };
20
- }
21
- else if (is(value, predicates.string) &&
22
- [...truthy, ...falsy].includes(value)) {
23
- return {
24
- parsable: true,
25
- parsed_value: truthy.includes(value),
26
- error: null,
27
- };
28
- }
29
- else if (is(value, predicates.undefined)) {
30
- return {
31
- parsable: true,
32
- parsed_value: false,
33
- error: null,
34
- };
35
- }
36
- else if (value === null) {
37
- return { parsable: true, parsed_value: false, error: null };
38
- }
39
- else {
40
- return {
41
- parsable: false,
42
- parsed_value: null,
43
- error: "Please enter a boolean",
44
- };
45
- }
46
- }
47
- getEmptyValue() {
48
- return false;
49
- }
50
- }
51
- //# sourceMappingURL=boolean.js.map
@@ -1,33 +0,0 @@
1
- import { describe, it } from "vitest";
2
- import assert from "assert";
3
- import { Fields } from "../../index.js";
4
- describe("boolean field", () => {
5
- const ctx = {};
6
- it("validation logic", async () => {
7
- const required = new Fields.Boolean(true);
8
- const not_required = new Fields.Boolean(false);
9
- assert.strictEqual((await required.isValueValid(ctx, true)).valid, true);
10
- assert.strictEqual((await required.isValueValid(ctx, false)).valid, false);
11
- assert.strictEqual((await not_required.isValueValid(ctx, true)).valid, true);
12
- assert.strictEqual((await not_required.isValueValid(ctx, false)).valid, true);
13
- });
14
- it("parse function", async () => {
15
- const field = new Fields.Boolean(true);
16
- const true_response = await field.parse(ctx, true);
17
- const null_response = await field.parse(ctx, null);
18
- const true_as_string_response = await field.parse(ctx, "true");
19
- const undefined_response = await field.parse(ctx, undefined);
20
- const number_response = await field.parse(ctx, 42);
21
- assert.strictEqual(true_response.parsable, true);
22
- assert.strictEqual(true_response.parsed_value, true);
23
- assert.strictEqual(null_response.parsable, true);
24
- assert.strictEqual(null_response.parsed_value, false);
25
- assert.strictEqual(true_as_string_response.parsable, true);
26
- assert.strictEqual(true_as_string_response.parsed_value, true);
27
- assert.strictEqual(undefined_response.parsable, true);
28
- assert.strictEqual(undefined_response.parsed_value, false);
29
- assert.strictEqual(number_response.parsable, false);
30
- assert.strictEqual(number_response.error, "Please enter a boolean");
31
- });
32
- });
33
- //# sourceMappingURL=boolean.test.js.map
@@ -1,40 +0,0 @@
1
- import { is, predicates } from "@sealcode/ts-predicates";
2
- import { FormField, } from "./field.js";
3
- export class ChekboxedListField extends FormField {
4
- constructor(required, generateOptions, isVisible = () => Promise.resolve(true)) {
5
- super(required);
6
- this.required = required;
7
- this.generateOptions = generateOptions;
8
- this.isVisible = isVisible;
9
- this.predicate = predicates.array(predicates.string); // TODO: this is probably wrong
10
- }
11
- async isValueValid(_, value) {
12
- if (is(value, predicates.string)) {
13
- return { valid: false, message: "you need an array" };
14
- }
15
- if (is(value, predicates.null)) {
16
- return { valid: false, message: "you need an array" };
17
- }
18
- return { valid: true, message: "" };
19
- }
20
- async parse(_, raw_value) {
21
- if (is(raw_value, predicates.object)) {
22
- return {
23
- parsable: true,
24
- parsed_value: Object.fromEntries(Object.entries(raw_value).filter(([, value]) => value === "on")),
25
- error: null,
26
- };
27
- }
28
- else {
29
- return {
30
- parsed_value: null,
31
- parsable: false,
32
- error: "Expected an object",
33
- };
34
- }
35
- }
36
- getEmptyValue() {
37
- return {};
38
- }
39
- }
40
- //# sourceMappingURL=checkboxed-list.js.map
@@ -1,29 +0,0 @@
1
- import { predicates } from "@sealcode/ts-predicates";
2
- import { FormField, } from "./field.js";
3
- export class CollectionField extends FormField {
4
- constructor(required, sealiousField) {
5
- super(required);
6
- this.sealiousField = sealiousField;
7
- this.predicate = predicates.unknown;
8
- }
9
- async parse(ctx, raw_value) {
10
- if (raw_value === undefined) {
11
- return { parsable: true, parsed_value: null, error: null };
12
- }
13
- const encoded_value = (await this.sealiousField.encode(ctx.$context, raw_value));
14
- const parsed_value = (await this.sealiousField.decode(ctx.$context, encoded_value, null, {}));
15
- return {
16
- parsable: true,
17
- error: null,
18
- parsed_value,
19
- };
20
- }
21
- async isValueValid(ctx, value) {
22
- const { valid, reason } = await this.sealiousField.checkValue(ctx.$context, value, undefined, null);
23
- return { valid, message: reason || (!valid ? "Wrong value" : "") };
24
- }
25
- getEmptyValue() {
26
- return "";
27
- }
28
- }
29
- //# sourceMappingURL=collection-field.js.map
@@ -1,11 +0,0 @@
1
- import { predicates } from "@sealcode/ts-predicates";
2
- import { RegExpField } from "./regexp.js";
3
- export class EmailField extends RegExpField {
4
- constructor(required, error_message = "Please enter a proper email address", default_value = "") {
5
- super(required, /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/, error_message, default_value);
6
- this.error_message = error_message;
7
- this.default_value = default_value;
8
- this.predicate = predicates.string;
9
- }
10
- }
11
- //# sourceMappingURL=email.js.map
@@ -1,20 +0,0 @@
1
- import assert from "assert";
2
- import { Fields } from "../../index.js";
3
- describe("email field", () => {
4
- const ctx = {};
5
- it("validation logic", async () => {
6
- const field = new Fields.EmailField(true);
7
- assert.strictEqual((await field.isValueValid(ctx, "yes@an.email")).valid, true);
8
- assert.strictEqual((await field.isValueValid(ctx, "notanemail")).valid, false);
9
- });
10
- it("parse function", async () => {
11
- const field = new Fields.EmailField(true);
12
- const string_response = await field.parse(ctx, "42");
13
- const number_response = await field.parse(ctx, 42);
14
- assert.strictEqual(string_response.parsable, true);
15
- assert.strictEqual(string_response.parsed_value, "42");
16
- assert.strictEqual(number_response.parsable, false);
17
- assert.strictEqual(number_response.error, "Please enter a string");
18
- });
19
- });
20
- //# sourceMappingURL=email.test.js.map
@@ -1,47 +0,0 @@
1
- import { is, predicates } from "@sealcode/ts-predicates";
2
- import { FormField } from "./field.js";
3
- export class EnumMultipleField extends FormField {
4
- constructor(required, options, error_message = (options) => options.join(", ")) {
5
- super(required);
6
- this.options = options;
7
- this.error_message = error_message;
8
- this.predicate = predicates.enum(this.options);
9
- }
10
- async isValueValid(_, values) {
11
- for (const value of values) {
12
- if (!is(value, predicates.string)) {
13
- return { valid: false, message: "expected a string" };
14
- }
15
- if (!this.options.includes(value)) {
16
- return { valid: false, message: "invalid value" };
17
- }
18
- }
19
- return { valid: true, message: "" };
20
- }
21
- async parse(_, value) {
22
- if (is(value, predicates.string)) {
23
- return { parsable: true, parsed_value: [value], error: null };
24
- }
25
- else if (is(value, predicates.array(predicates.string))) {
26
- return {
27
- parsable: true,
28
- parsed_value: value,
29
- error: null,
30
- };
31
- }
32
- else if (value == null) {
33
- return { parsable: true, parsed_value: [], error: null };
34
- }
35
- else {
36
- return {
37
- parsable: false,
38
- parsed_value: null,
39
- error: "Please enter a list of strings",
40
- };
41
- }
42
- }
43
- getEmptyValue() {
44
- return [];
45
- }
46
- }
47
- //# sourceMappingURL=enum-multiple.js.map
@@ -1,27 +0,0 @@
1
- import assert from "assert";
2
- import { Fields } from "../../index.js";
3
- describe("enum-multiple field", () => {
4
- const ctx = {};
5
- it("validation logic", async () => {
6
- const field = new Fields.EnumMultipleField(true, ["sa", "mp", "le"]);
7
- assert.strictEqual((await field.isValueValid(ctx, ["sa", "le"])).valid, true);
8
- assert.strictEqual((await field.isValueValid(ctx, ["notvalid"])).valid, false);
9
- assert.strictEqual((await field.isValueValid(ctx, [42])).valid, false);
10
- });
11
- it("parse function", async () => {
12
- const field = new Fields.EnumMultipleField(true, []);
13
- const string_array_response = await field.parse(ctx, ["42"]);
14
- const number_response = await field.parse(ctx, 42);
15
- const string_response = await field.parse(ctx, "sample");
16
- const null_response = await field.parse(ctx, null);
17
- assert.strictEqual(string_array_response.parsable, true);
18
- assert.deepEqual(string_array_response.parsed_value, ["42"]);
19
- assert.strictEqual(number_response.parsable, false);
20
- assert.strictEqual(number_response.error, "Please enter a list of strings");
21
- assert.strictEqual(string_response.parsable, true);
22
- assert.deepEqual(string_response.parsed_value, ["sample"]);
23
- assert.strictEqual(null_response.parsable, true);
24
- assert.deepEqual(null_response.parsed_value, []);
25
- });
26
- });
27
- //# sourceMappingURL=enum-multiple.test.js.map
@@ -1,39 +0,0 @@
1
- import { is, predicates } from "@sealcode/ts-predicates";
2
- import { FormField } from "./field.js";
3
- export class EnumField extends FormField {
4
- constructor(required, options, error_message = (options) => options.join(", ")) {
5
- super(required);
6
- this.options = options;
7
- this.error_message = error_message;
8
- this.predicate = predicates.enum(this.options);
9
- }
10
- async isValueValid(_, value) {
11
- if (!is(value, predicates.string)) {
12
- return { valid: false, message: "expected a string" };
13
- }
14
- if (this.options.includes(value)) {
15
- return { valid: true, message: "" };
16
- }
17
- return { valid: false, message: this.error_message(this.options) };
18
- }
19
- async parse(_, value) {
20
- if (is(value, predicates.string)) {
21
- return {
22
- parsable: true,
23
- parsed_value: value,
24
- error: null,
25
- };
26
- }
27
- else {
28
- return {
29
- parsable: false,
30
- parsed_value: null,
31
- error: "Please enter a string",
32
- };
33
- }
34
- }
35
- getEmptyValue() {
36
- return "";
37
- }
38
- }
39
- //# sourceMappingURL=enum.js.map
@@ -1,21 +0,0 @@
1
- import assert from "assert";
2
- import { Fields } from "../../index.js";
3
- describe("enum field", () => {
4
- const ctx = {};
5
- it("validation logic", async () => {
6
- const field = new Fields.EnumField(true, ["sa", "mp", "le"]);
7
- assert.strictEqual((await field.isValueValid(ctx, 42)).valid, false);
8
- assert.strictEqual((await field.isValueValid(ctx, "mp")).valid, true);
9
- assert.strictEqual((await field.isValueValid(ctx, "notvalid")).valid, false);
10
- });
11
- it("parse function", async () => {
12
- const field = new Fields.EnumField(true, []);
13
- const string_response = await field.parse(ctx, "42");
14
- const number_response = await field.parse(ctx, 42);
15
- assert.strictEqual(string_response.parsable, true);
16
- assert.strictEqual(string_response.parsed_value, "42");
17
- assert.strictEqual(number_response.parsable, false);
18
- assert.strictEqual(number_response.error, "Please enter a string");
19
- });
20
- });
21
- //# sourceMappingURL=enum.test.js.map
@@ -1,16 +0,0 @@
1
- import { PickFromListField } from "./pick-from-list.js";
2
- export class ExistingSealiousValue extends PickFromListField {
3
- constructor(required, field) {
4
- super(required, async (ctx) => {
5
- const { items } = await field.collection.list(ctx.$context).fetch();
6
- return Object.fromEntries(items.map((item) => {
7
- const value = item.get(field.name);
8
- return [value, value];
9
- }));
10
- });
11
- }
12
- getEmptyValue() {
13
- return "";
14
- }
15
- }
16
- //# sourceMappingURL=existing-sealious-value.js.map
@@ -1,66 +0,0 @@
1
- import { predicates } from "@sealcode/ts-predicates";
2
- import { t } from "../../utils/translate.js";
3
- export function fieldsToShape(obj) {
4
- return Object.fromEntries(Object.entries(obj).map(([key, value]) => [key, value.predicate]));
5
- }
6
- export class FormField {
7
- constructor(required) {
8
- this.required = required;
9
- this.predicate = predicates.unknown;
10
- this.mapToFilter = (value) => value;
11
- }
12
- async init(fieldname) {
13
- this.name = fieldname;
14
- }
15
- async _validate(ctx, value) {
16
- if (this.required &&
17
- (value === "" || value === null || value === undefined)) {
18
- return {
19
- valid: false,
20
- message: t(ctx, "field_is_required", [], "This field is required"),
21
- };
22
- }
23
- return this.isValueValid(ctx, value);
24
- }
25
- async isValueValid(ctx, value) {
26
- return { valid: true, message: "" };
27
- }
28
- async getValue(ctx, all_form_values) {
29
- if (Object.keys(all_form_values || {}).length === 0) {
30
- // don't validate on virgin form
31
- return {
32
- parsed: this.getEmptyValue(),
33
- valid: true,
34
- message: "",
35
- raw: "",
36
- };
37
- }
38
- const raw = all_form_values[this.name];
39
- const { parsable, parsed_value, error: parse_error, } = await this.parse(ctx, raw);
40
- if (!parsable) {
41
- return {
42
- valid: false,
43
- parsed: this.getEmptyValue(),
44
- raw,
45
- message: parse_error || "Error",
46
- };
47
- }
48
- const { valid, message } = await this._validate(ctx, parsed_value);
49
- return {
50
- parsed: parsed_value,
51
- valid,
52
- message,
53
- raw: all_form_values[this.name],
54
- };
55
- }
56
- setMapToFilter(fn) {
57
- this.mapToFilter = fn;
58
- return this;
59
- }
60
- //return undefined here to delete a value
61
- async getDatabaseValue(ctx, data) {
62
- const { parsed } = await this.getValue(ctx, data);
63
- return parsed;
64
- }
65
- }
66
- //# sourceMappingURL=field.js.map
@@ -1,16 +0,0 @@
1
- export * from "./simple-form-field.js";
2
- export * from "./checkboxed-list.js";
3
- export * from "./collection-field.js";
4
- export * from "./number.js";
5
- export * from "./pick-from-list.js";
6
- export * from "./regexp.js";
7
- export * from "./email.js";
8
- export * from "./enum.js";
9
- export * from "./boolean.js";
10
- export * from "./enum-multiple.js";
11
- export * from "./existing-sealious-value.js";
12
- export * from "./file.js";
13
- export * from "./multiple-files.js";
14
- export * from "./reverse-single-reference.js";
15
- export * from "./structured-array.js";
16
- //# sourceMappingURL=fields.js.map
@@ -1,53 +0,0 @@
1
- import { hasFieldOfType, hasShape, is, predicates, } from "@sealcode/ts-predicates";
2
- import { File as SealiousFile } from "sealious";
3
- import { FormField } from "./field.js";
4
- export class File extends FormField {
5
- async parse(ctx, raw_value) {
6
- let result;
7
- if (raw_value instanceof SealiousFile ||
8
- (is(raw_value, predicates.object) &&
9
- hasShape({
10
- filename: predicates.string,
11
- id: predicates.string,
12
- }, raw_value) &&
13
- raw_value.id)) {
14
- const file = await SealiousFile.fromID(ctx.$app, raw_value.id);
15
- result = {
16
- parsed_value: { old: file, new: null },
17
- error: null,
18
- parsable: true,
19
- };
20
- }
21
- else if (!is(raw_value, predicates.object)) {
22
- result = {
23
- parsed_value: null,
24
- error: "Expected a field with old.id:string, old.filename:string and new?:File",
25
- parsable: false,
26
- };
27
- }
28
- else {
29
- const old_file = hasFieldOfType(raw_value, "old", predicates.object) &&
30
- hasShape({ id: predicates.string, filename: predicates.string }, raw_value.old) &&
31
- raw_value.old.id
32
- ? await SealiousFile.fromID(ctx.$app, raw_value.old.id)
33
- : null;
34
- const new_file = hasFieldOfType(raw_value, "new", predicates.array(predicates.object)) && raw_value.new[0] instanceof SealiousFile
35
- ? raw_value.new[0]
36
- : null;
37
- result = {
38
- parsable: true,
39
- error: null,
40
- parsed_value: { old: old_file, new: new_file },
41
- };
42
- }
43
- return result;
44
- }
45
- async getDatabaseValue(ctx, data) {
46
- const { parsed } = await this.getValue(ctx, data);
47
- return parsed.new || undefined;
48
- }
49
- getEmptyValue() {
50
- return { old: null, new: null };
51
- }
52
- }
53
- //# sourceMappingURL=file.js.map
@@ -1,15 +0,0 @@
1
- import { FormField } from "./field.js";
2
- export class MultipleFiles extends FormField {
3
- constructor(collection_field, getItemId) {
4
- super(false);
5
- this.collection_field = collection_field;
6
- this.getItemId = getItemId;
7
- }
8
- getEmptyValue() {
9
- return undefined;
10
- }
11
- async parse() {
12
- return { parsed_value: undefined, parsable: true, error: null }; // the control is supposed to do the heavy lifting here
13
- }
14
- }
15
- //# sourceMappingURL=multiple-files.js.map
@@ -1,45 +0,0 @@
1
- import { is, predicates } from "@sealcode/ts-predicates";
2
- import { FormField } from "./field.js";
3
- export class NumberField extends FormField {
4
- constructor(required, default_value, options = {}) {
5
- super(required);
6
- this.default_value = default_value;
7
- this.options = options;
8
- this.predicate = predicates.number;
9
- }
10
- async isValueValid(_, value) {
11
- if ((is(value, predicates.string) &&
12
- !isNaN(parseFloat(value)) &&
13
- parseFloat(value).toString() == value.trim()) ||
14
- is(value, predicates.number) ||
15
- ((is(value, predicates.undefined) || value == "") && !this.required)) {
16
- return { valid: true, message: "" };
17
- }
18
- return { valid: false, message: "Proszę wprowadzić liczbę" };
19
- }
20
- async parse(_, value) {
21
- if ((is(value, predicates.string) &&
22
- !isNaN(parseFloat(value)) &&
23
- parseFloat(value).toString() == value.trim()) ||
24
- is(value, predicates.number)) {
25
- return {
26
- parsable: true,
27
- parsed_value: this.options.decimalDigits
28
- ? parseFloat(parseFloat(value.toString()).toFixed(this.options.decimalDigits))
29
- : parseFloat(value.toString()),
30
- error: null,
31
- };
32
- }
33
- else {
34
- return {
35
- parsable: false,
36
- parsed_value: null,
37
- error: "Please enter a number",
38
- };
39
- }
40
- }
41
- getEmptyValue() {
42
- return this.default_value;
43
- }
44
- }
45
- //# sourceMappingURL=number.js.map
@@ -1,31 +0,0 @@
1
- import assert from "assert";
2
- import * as Sealgen from "../../index.js";
3
- const { Fields } = Sealgen;
4
- describe("number field", () => {
5
- const ctx = {};
6
- it("validation logic", async () => {
7
- const required = new Fields.NumberField(true, 0);
8
- const not_required = new Fields.NumberField(false, 0);
9
- assert.strictEqual((await required.isValueValid(ctx, 42)).valid, true);
10
- assert.strictEqual((await required.isValueValid(ctx, "42")).valid, true);
11
- assert.strictEqual((await required.isValueValid(ctx, "notvalid")).valid, false);
12
- assert.strictEqual((await not_required.isValueValid(ctx, "")).valid, true);
13
- });
14
- it("parse function", async () => {
15
- const required = new Fields.NumberField(true, 0);
16
- const decimal_digits = new Fields.NumberField(true, 0, { decimalDigits: 1 });
17
- const number_as_string_response = await required.parse(ctx, "42");
18
- const number_response = await required.parse(ctx, 42);
19
- const not_a_number_response = await required.parse(ctx, "notanumber");
20
- const decimal_number_response = await decimal_digits.parse(ctx, 42.42);
21
- assert.strictEqual(number_as_string_response.parsable, true);
22
- assert.strictEqual(number_as_string_response.parsed_value, 42);
23
- assert.strictEqual(number_response.parsable, true);
24
- assert.strictEqual(number_response.parsed_value, 42);
25
- assert.strictEqual(not_a_number_response.parsable, false);
26
- assert.strictEqual(not_a_number_response.error, "Please enter a number");
27
- assert.strictEqual(decimal_number_response.parsable, true);
28
- assert.strictEqual(decimal_number_response.parsed_value, 42.4);
29
- });
30
- });
31
- //# sourceMappingURL=number.test.js.map