@sealcode/sealgen 0.12.0 → 0.12.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 (268) hide show
  1. package/dist/notifier.js +1 -1
  2. package/package.json +2 -2
  3. package/src/notifier.ts +1 -1
  4. package/.madgerc +0 -7
  5. package/coverage/.tmp/coverage-15.json +0 -1
  6. package/coverage/.tmp/coverage-16.json +0 -1
  7. package/coverage/.tmp/coverage-17.json +0 -1
  8. package/coverage/.tmp/coverage-18.json +0 -1
  9. package/coverage/.tmp/coverage-19.json +0 -1
  10. package/coverage/.tmp/coverage-20.json +0 -1
  11. package/coverage/.tmp/coverage-21.json +0 -1
  12. package/coverage/.tmp/coverage-22.json +0 -1
  13. package/coverage/.tmp/coverage-23.json +0 -1
  14. package/coverage/.tmp/coverage-24.json +0 -1
  15. package/coverage/.tmp/coverage-25.json +0 -1
  16. package/coverage/.tmp/coverage-26.json +0 -1
  17. package/lib/add-collection.js +0 -24
  18. package/lib/add-jdd-component.js +0 -27
  19. package/lib/add-route.js +0 -65
  20. package/lib/add-route.test.js +0 -60
  21. package/lib/build.js +0 -187
  22. package/lib/cli.js +0 -35
  23. package/lib/components/components.js +0 -3
  24. package/lib/components/tabs.js +0 -88
  25. package/lib/components/toggle-modal.js +0 -46
  26. package/lib/example.test.js +0 -5
  27. package/lib/find-css-includes.js +0 -23
  28. package/lib/forms/controls/array.js +0 -140
  29. package/lib/forms/controls/autocomplete.js +0 -23
  30. package/lib/forms/controls/big-radio-group.js +0 -34
  31. package/lib/forms/controls/checkbox-group.js +0 -29
  32. package/lib/forms/controls/checkbox.js +0 -24
  33. package/lib/forms/controls/checkboxed-list-input.js +0 -35
  34. package/lib/forms/controls/collapsible-checkbox-group.js +0 -13
  35. package/lib/forms/controls/collapsible-field-group.js +0 -78
  36. package/lib/forms/controls/controls.js +0 -31
  37. package/lib/forms/controls/derived-frame.js +0 -52
  38. package/lib/forms/controls/derived.js +0 -77
  39. package/lib/forms/controls/dropdown.js +0 -55
  40. package/lib/forms/controls/editable-collection-subset.js +0 -68
  41. package/lib/forms/controls/field-group.js +0 -53
  42. package/lib/forms/controls/file.js +0 -35
  43. package/lib/forms/controls/form-control.js +0 -14
  44. package/lib/forms/controls/form-field-control.js +0 -9
  45. package/lib/forms/controls/form-header.js +0 -14
  46. package/lib/forms/controls/form-paragraph.js +0 -12
  47. package/lib/forms/controls/frame.js +0 -25
  48. package/lib/forms/controls/hidden-input.js +0 -14
  49. package/lib/forms/controls/html.js +0 -23
  50. package/lib/forms/controls/multiple-files.js +0 -160
  51. package/lib/forms/controls/multiple-photos.js +0 -33
  52. package/lib/forms/controls/number.js +0 -25
  53. package/lib/forms/controls/photo.js +0 -57
  54. package/lib/forms/controls/radio.js +0 -25
  55. package/lib/forms/controls/reverse-single-reference.js +0 -47
  56. package/lib/forms/controls/simple-input.js +0 -78
  57. package/lib/forms/controls/textarea.js +0 -33
  58. package/lib/forms/controls/tickable.js +0 -75
  59. package/lib/forms/fields/boolean.js +0 -51
  60. package/lib/forms/fields/boolean.test.js +0 -32
  61. package/lib/forms/fields/checkboxed-list.js +0 -40
  62. package/lib/forms/fields/collection-field.js +0 -29
  63. package/lib/forms/fields/email.js +0 -11
  64. package/lib/forms/fields/email.test.js +0 -20
  65. package/lib/forms/fields/enum-multiple.js +0 -47
  66. package/lib/forms/fields/enum-multiple.test.js +0 -27
  67. package/lib/forms/fields/enum.js +0 -39
  68. package/lib/forms/fields/enum.test.js +0 -21
  69. package/lib/forms/fields/existing-sealious-value.js +0 -16
  70. package/lib/forms/fields/field.js +0 -81
  71. package/lib/forms/fields/file.js +0 -53
  72. package/lib/forms/fields/multiple-files.js +0 -15
  73. package/lib/forms/fields/number.js +0 -45
  74. package/lib/forms/fields/number.test.js +0 -30
  75. package/lib/forms/fields/pick-from-list.js +0 -31
  76. package/lib/forms/fields/pick-from-list.test.js +0 -17
  77. package/lib/forms/fields/proxy-field.js +0 -20
  78. package/lib/forms/fields/regexp.js +0 -40
  79. package/lib/forms/fields/regexp.test.js +0 -21
  80. package/lib/forms/fields/reverse-single-reference.js +0 -14
  81. package/lib/forms/fields/simple-form-field.js +0 -20
  82. package/lib/forms/fields/structured-array.js +0 -18
  83. package/lib/forms/form.js +0 -176
  84. package/lib/forms/form.test.js +0 -1
  85. package/lib/forms/multiform.js +0 -174
  86. package/lib/forms/multiform.test.js +0 -426
  87. package/lib/generate-collections.js +0 -52
  88. package/lib/generate-components.js +0 -33
  89. package/lib/generate-routes.js +0 -75
  90. package/lib/index.js +0 -17
  91. package/lib/make-env.js +0 -14
  92. package/lib/make-hidden-inputs.js +0 -14
  93. package/lib/mount.js +0 -70
  94. package/lib/notifier.js +0 -19
  95. package/lib/page/access-control.js +0 -16
  96. package/lib/page/default-list-filters.js +0 -40
  97. package/lib/page/list.js +0 -183
  98. package/lib/page/mountable-with-fields.js +0 -85
  99. package/lib/page/mountable.js +0 -5
  100. package/lib/page/page.js +0 -26
  101. package/lib/page/props-parser.js +0 -23
  102. package/lib/page/sealious-list.js +0 -59
  103. package/lib/page/stateful-page.js +0 -97
  104. package/lib/remove-named-imports.js +0 -47
  105. package/lib/run.js +0 -2
  106. package/lib/sanitize.js +0 -10
  107. package/lib/src/add-collection.js +0 -24
  108. package/lib/src/add-jdd-component.js +0 -27
  109. package/lib/src/add-route.js +0 -65
  110. package/lib/src/add-route.test.js +0 -72
  111. package/lib/src/build.js +0 -142
  112. package/lib/src/cli.js +0 -37
  113. package/lib/src/components/components.js +0 -3
  114. package/lib/src/components/tabs.js +0 -88
  115. package/lib/src/components/toggle-modal.js +0 -46
  116. package/lib/src/example.test.js +0 -5
  117. package/lib/src/find-css-includes.js +0 -23
  118. package/lib/src/forms/controls/array.js +0 -141
  119. package/lib/src/forms/controls/autocomplete.js +0 -23
  120. package/lib/src/forms/controls/big-radio-group.js +0 -34
  121. package/lib/src/forms/controls/checkbox-group.js +0 -30
  122. package/lib/src/forms/controls/checkbox.js +0 -24
  123. package/lib/src/forms/controls/checkboxed-list-input.js +0 -35
  124. package/lib/src/forms/controls/collapsible-checkbox-group.js +0 -13
  125. package/lib/src/forms/controls/collapsible-field-group.js +0 -78
  126. package/lib/src/forms/controls/controls.js +0 -31
  127. package/lib/src/forms/controls/derived-frame.js +0 -52
  128. package/lib/src/forms/controls/derived.js +0 -77
  129. package/lib/src/forms/controls/dropdown.js +0 -55
  130. package/lib/src/forms/controls/editable-collection-subset.js +0 -68
  131. package/lib/src/forms/controls/field-group.js +0 -53
  132. package/lib/src/forms/controls/file.js +0 -35
  133. package/lib/src/forms/controls/form-control.js +0 -14
  134. package/lib/src/forms/controls/form-field-control.js +0 -9
  135. package/lib/src/forms/controls/form-header.js +0 -14
  136. package/lib/src/forms/controls/form-paragraph.js +0 -12
  137. package/lib/src/forms/controls/frame.js +0 -25
  138. package/lib/src/forms/controls/hidden-input.js +0 -14
  139. package/lib/src/forms/controls/html.js +0 -23
  140. package/lib/src/forms/controls/multiple-files.js +0 -160
  141. package/lib/src/forms/controls/multiple-photos.js +0 -33
  142. package/lib/src/forms/controls/number.js +0 -25
  143. package/lib/src/forms/controls/photo.js +0 -57
  144. package/lib/src/forms/controls/radio.js +0 -25
  145. package/lib/src/forms/controls/reverse-single-reference.js +0 -47
  146. package/lib/src/forms/controls/simple-input.js +0 -78
  147. package/lib/src/forms/controls/textarea.js +0 -33
  148. package/lib/src/forms/controls/tickable.js +0 -75
  149. package/lib/src/forms/fields/boolean.js +0 -51
  150. package/lib/src/forms/fields/boolean.test.js +0 -33
  151. package/lib/src/forms/fields/checkboxed-list.js +0 -40
  152. package/lib/src/forms/fields/collection-field.js +0 -29
  153. package/lib/src/forms/fields/email.js +0 -11
  154. package/lib/src/forms/fields/email.test.js +0 -20
  155. package/lib/src/forms/fields/enum-multiple.js +0 -47
  156. package/lib/src/forms/fields/enum-multiple.test.js +0 -27
  157. package/lib/src/forms/fields/enum.js +0 -39
  158. package/lib/src/forms/fields/enum.test.js +0 -21
  159. package/lib/src/forms/fields/existing-sealious-value.js +0 -16
  160. package/lib/src/forms/fields/field.js +0 -66
  161. package/lib/src/forms/fields/fields.js +0 -16
  162. package/lib/src/forms/fields/file.js +0 -53
  163. package/lib/src/forms/fields/multiple-files.js +0 -15
  164. package/lib/src/forms/fields/number.js +0 -45
  165. package/lib/src/forms/fields/number.test.js +0 -31
  166. package/lib/src/forms/fields/pick-from-list.js +0 -31
  167. package/lib/src/forms/fields/pick-from-list.test.js +0 -17
  168. package/lib/src/forms/fields/proxy-field.js +0 -20
  169. package/lib/src/forms/fields/regexp.js +0 -40
  170. package/lib/src/forms/fields/regexp.test.js +0 -21
  171. package/lib/src/forms/fields/reverse-single-reference.js +0 -14
  172. package/lib/src/forms/fields/simple-form-field.js +0 -19
  173. package/lib/src/forms/fields/structured-array.js +0 -18
  174. package/lib/src/forms/form-types.js +0 -2
  175. package/lib/src/forms/form.js +0 -176
  176. package/lib/src/forms/form.test.js +0 -271
  177. package/lib/src/forms/multiform.js +0 -174
  178. package/lib/src/forms/multiform.test.js +0 -430
  179. package/lib/src/generate-collections.js +0 -52
  180. package/lib/src/generate-components.js +0 -33
  181. package/lib/src/generate-routes.js +0 -75
  182. package/lib/src/hehe.test.js +0 -7
  183. package/lib/src/index.js +0 -19
  184. package/lib/src/make-env.js +0 -14
  185. package/lib/src/make-hidden-inputs.js +0 -14
  186. package/lib/src/mount.js +0 -70
  187. package/lib/src/notifier.js +0 -19
  188. package/lib/src/page/access-control.js +0 -16
  189. package/lib/src/page/default-list-filters.js +0 -40
  190. package/lib/src/page/list.js +0 -184
  191. package/lib/src/page/mountable-with-fields.js +0 -85
  192. package/lib/src/page/mountable.js +0 -5
  193. package/lib/src/page/page.js +0 -26
  194. package/lib/src/page/props-parser.js +0 -23
  195. package/lib/src/page/sealious-list.js +0 -59
  196. package/lib/src/page/stateful-page.js +0 -97
  197. package/lib/src/run.js +0 -2
  198. package/lib/src/sample-index.js +0 -3
  199. package/lib/src/sample-lib.js +0 -6
  200. package/lib/src/sanitize.js +0 -10
  201. package/lib/src/templates/collection.js +0 -12
  202. package/lib/src/templates/form.js +0 -57
  203. package/lib/src/templates/jdd-component.js +0 -39
  204. package/lib/src/templates/list.js +0 -139
  205. package/lib/src/templates/long-running-process.js +0 -60
  206. package/lib/src/templates/multiform.js +0 -55
  207. package/lib/src/templates/page.js +0 -23
  208. package/lib/src/templates/post.js +0 -22
  209. package/lib/src/templates/redirect.js +0 -23
  210. package/lib/src/templates/route-test.js +0 -54
  211. package/lib/src/templates/stateful-page.js +0 -66
  212. package/lib/src/templates/templates.js +0 -21
  213. package/lib/src/test_utils/locator_is_visible.js +0 -11
  214. package/lib/src/utils/assert-throws.js +0 -17
  215. package/lib/src/utils/base64.js +0 -7
  216. package/lib/src/utils/browser-creator.js +0 -10
  217. package/lib/src/utils/escape-url-params.js +0 -14
  218. package/lib/src/utils/exec.js +0 -22
  219. package/lib/src/utils/extract-fields-from-collection.js +0 -26
  220. package/lib/src/utils/format-external-url.js +0 -11
  221. package/lib/src/utils/import-path.js +0 -16
  222. package/lib/src/utils/input-wrapper.js +0 -15
  223. package/lib/src/utils/list-collections.js +0 -13
  224. package/lib/src/utils/make-slug.js +0 -6
  225. package/lib/src/utils/natural-numbers.js +0 -6
  226. package/lib/src/utils/prettier.js +0 -10
  227. package/lib/src/utils/question.js +0 -19
  228. package/lib/src/utils/render-attributes.js +0 -19
  229. package/lib/src/utils/sleep.js +0 -4
  230. package/lib/src/utils/translate.js +0 -6
  231. package/lib/src/utils/url-with-new-params.js +0 -5
  232. package/lib/src/utils/utils.js +0 -16
  233. package/lib/src/utils/walk.js +0 -23
  234. package/lib/src/vitest.config.js +0 -20
  235. package/lib/templates/collection.js +0 -12
  236. package/lib/templates/form.js +0 -57
  237. package/lib/templates/jdd-component.js +0 -39
  238. package/lib/templates/list.js +0 -139
  239. package/lib/templates/long-running-process.js +0 -60
  240. package/lib/templates/multiform.js +0 -55
  241. package/lib/templates/page.js +0 -23
  242. package/lib/templates/post.js +0 -22
  243. package/lib/templates/redirect.js +0 -23
  244. package/lib/templates/route-test.js +0 -54
  245. package/lib/templates/stateful-page.js +0 -66
  246. package/lib/templates/templates.js +0 -21
  247. package/lib/test_utils/locator_is_visible.js +0 -11
  248. package/lib/utils/assert-throws.js +0 -17
  249. package/lib/utils/base64.js +0 -7
  250. package/lib/utils/browser-creator.js +0 -10
  251. package/lib/utils/escape-url-params.js +0 -14
  252. package/lib/utils/exec.js +0 -22
  253. package/lib/utils/extract-fields-from-collection.js +0 -26
  254. package/lib/utils/format-external-url.js +0 -11
  255. package/lib/utils/import-path.js +0 -16
  256. package/lib/utils/input-wrapper.js +0 -15
  257. package/lib/utils/list-collections.js +0 -13
  258. package/lib/utils/make-slug.js +0 -6
  259. package/lib/utils/natural-numbers.js +0 -6
  260. package/lib/utils/prettier.js +0 -10
  261. package/lib/utils/question.js +0 -19
  262. package/lib/utils/render-attributes.js +0 -19
  263. package/lib/utils/sleep.js +0 -4
  264. package/lib/utils/translate.js +0 -6
  265. package/lib/utils/url-with-new-params.js +0 -5
  266. package/lib/utils/utils.js +0 -16
  267. package/lib/utils/walk.js +0 -23
  268. package/lib/vitest.config.js +0 -22
@@ -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,81 +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
- export * from "./simple-form-field.js";
67
- export * from "./checkboxed-list.js";
68
- export * from "./collection-field.js";
69
- export * from "./number.js";
70
- export * from "./pick-from-list.js";
71
- export * from "./regexp.js";
72
- export * from "./email.js";
73
- export * from "./enum.js";
74
- export * from "./boolean.js";
75
- export * from "./enum-multiple.js";
76
- export * from "./existing-sealious-value.js";
77
- export * from "./file.js";
78
- export * from "./multiple-files.js";
79
- export * from "./reverse-single-reference.js";
80
- export * from "./structured-array.js";
81
- //# sourceMappingURL=field.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,30 +0,0 @@
1
- import assert from "assert";
2
- import { Fields } from "../../index.js";
3
- describe("number field", () => {
4
- const ctx = {};
5
- it("validation logic", async () => {
6
- const required = new Fields.NumberField(true, 0);
7
- const not_required = new Fields.NumberField(false, 0);
8
- assert.strictEqual((await required.isValueValid(ctx, 42)).valid, true);
9
- assert.strictEqual((await required.isValueValid(ctx, "42")).valid, true);
10
- assert.strictEqual((await required.isValueValid(ctx, "notvalid")).valid, false);
11
- assert.strictEqual((await not_required.isValueValid(ctx, "")).valid, true);
12
- });
13
- it("parse function", async () => {
14
- const required = new Fields.NumberField(true, 0);
15
- const decimal_digits = new Fields.NumberField(true, 0, { decimalDigits: 1 });
16
- const number_as_string_response = await required.parse(ctx, "42");
17
- const number_response = await required.parse(ctx, 42);
18
- const not_a_number_response = await required.parse(ctx, "notanumber");
19
- const decimal_number_response = await decimal_digits.parse(ctx, 42.42);
20
- assert.strictEqual(number_as_string_response.parsable, true);
21
- assert.strictEqual(number_as_string_response.parsed_value, 42);
22
- assert.strictEqual(number_response.parsable, true);
23
- assert.strictEqual(number_response.parsed_value, 42);
24
- assert.strictEqual(not_a_number_response.parsable, false);
25
- assert.strictEqual(not_a_number_response.error, "Please enter a number");
26
- assert.strictEqual(decimal_number_response.parsable, true);
27
- assert.strictEqual(decimal_number_response.parsed_value, 42.4);
28
- });
29
- });
30
- //# sourceMappingURL=number.test.js.map
@@ -1,31 +0,0 @@
1
- import { is, predicates } from "@sealcode/ts-predicates";
2
- import { SimpleFormField } from "./simple-form-field.js";
3
- export class PickFromListField extends SimpleFormField {
4
- constructor(required, generateOptions, customValidation = (ctx, value, instance) => instance.valueInList(ctx, value)) {
5
- super(required);
6
- this.required = required;
7
- this.generateOptions = generateOptions;
8
- this.customValidation = customValidation;
9
- this.predicate = predicates.string;
10
- }
11
- isValueValid(ctx, value) {
12
- return this.customValidation(ctx, value, this);
13
- }
14
- async valueInList(ctx, value) {
15
- const options = await this.generateOptions(ctx);
16
- if (!is(value, predicates.string)) {
17
- return { valid: false, message: "not a string" };
18
- }
19
- if (this.required && !options.map((o) => o.value).includes(value)) {
20
- return {
21
- valid: false,
22
- message: `"${value}" is not one of the options`,
23
- };
24
- }
25
- return { valid: true, message: "" };
26
- }
27
- getEmptyValue() {
28
- return "";
29
- }
30
- }
31
- //# sourceMappingURL=pick-from-list.js.map
@@ -1,17 +0,0 @@
1
- import assert from "assert";
2
- import { Fields } from "../../index.js";
3
- describe("pick-from-list field", () => {
4
- const ctx = {};
5
- it("validation logic", async () => {
6
- const field = new Fields.PickFromListField(true, async () => {
7
- return [
8
- { value: "samplev", label: "samplel" },
9
- { value: "samplevv", label: "samplell" },
10
- ];
11
- });
12
- assert.strictEqual((await field.isValueValid(ctx, 42)).valid, false);
13
- assert.strictEqual((await field.isValueValid(ctx, "samplevv")).valid, true);
14
- assert.strictEqual((await field.isValueValid(ctx, "notvalid")).valid, false);
15
- });
16
- });
17
- //# sourceMappingURL=pick-from-list.test.js.map
@@ -1,20 +0,0 @@
1
- import { FormField } from "./field.js";
2
- export class ProxyFormField extends FormField {
3
- constructor(required, name, empty_value, parsed_value) {
4
- super(required);
5
- this.name = name;
6
- this.empty_value = empty_value;
7
- this.parsed_value = parsed_value;
8
- }
9
- getEmptyValue() {
10
- return this.empty_value;
11
- }
12
- async parse() {
13
- return {
14
- parsable: true,
15
- error: null,
16
- parsed_value: this.parsed_value,
17
- };
18
- }
19
- }
20
- //# sourceMappingURL=proxy-field.js.map
@@ -1,40 +0,0 @@
1
- import { is, predicates } from "@sealcode/ts-predicates";
2
- import { FormField } from "./field.js";
3
- export class RegExpField extends FormField {
4
- constructor(required, regexp, error_message, default_value = "") {
5
- super(required);
6
- this.regexp = regexp;
7
- this.error_message = error_message;
8
- this.default_value = default_value;
9
- this.predicate = predicates.string;
10
- }
11
- async isValueValid(_, value) {
12
- if (!is(value, predicates.string)) {
13
- return { valid: false, message: "expected a string" };
14
- }
15
- if (this.regexp.exec(value)) {
16
- return { valid: true, message: "" };
17
- }
18
- return { valid: false, message: this.error_message };
19
- }
20
- async parse(_, value) {
21
- if (is(value, predicates.string)) {
22
- return {
23
- parsable: true,
24
- parsed_value: value,
25
- error: null,
26
- };
27
- }
28
- else {
29
- return {
30
- parsable: false,
31
- parsed_value: null,
32
- error: "Please enter a string",
33
- };
34
- }
35
- }
36
- getEmptyValue() {
37
- return this.default_value || "";
38
- }
39
- }
40
- //# sourceMappingURL=regexp.js.map
@@ -1,21 +0,0 @@
1
- import assert from "assert";
2
- import { Fields } from "../../index.js";
3
- describe("regexp field", () => {
4
- const ctx = {};
5
- it("validation logic", async () => {
6
- const field = new Fields.RegExpField(true, /^4/, "error");
7
- assert.strictEqual((await field.isValueValid(ctx, "42")).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.RegExpField(true, /^4/, "error");
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=regexp.test.js.map
@@ -1,14 +0,0 @@
1
- import { FormField } from "./field.js";
2
- export class ReverseSingleReference extends FormField {
3
- constructor(required, sealious_field) {
4
- super(required);
5
- this.sealious_field = sealious_field;
6
- }
7
- async parse(ctx, raw_value) {
8
- return { parsable: true, error: null, parsed_value: raw_value };
9
- }
10
- getEmptyValue() {
11
- return [];
12
- }
13
- }
14
- //# sourceMappingURL=reverse-single-reference.js.map
@@ -1,20 +0,0 @@
1
- import { FormField } from "./field.js";
2
- import { predicates } from "@sealcode/ts-predicates";
3
- console.log({ FormField });
4
- export class SimpleFormField extends FormField {
5
- async parse(_, raw_value) {
6
- return {
7
- parsed_value: (raw_value || "").toString(),
8
- parsable: true,
9
- error: null,
10
- };
11
- }
12
- getEmptyValue() {
13
- return "";
14
- }
15
- constructor(required) {
16
- super(required);
17
- this.predicate = predicates.string;
18
- }
19
- }
20
- //# sourceMappingURL=simple-form-field.js.map
@@ -1,18 +0,0 @@
1
- import { FormField } from "./field.js";
2
- export class StructuredArrayField extends FormField {
3
- constructor(sealious_field) {
4
- super(true);
5
- this.sealious_field = sealious_field;
6
- }
7
- async parse(context, value) {
8
- return {
9
- parsable: true,
10
- error: null,
11
- parsed_value: value || [],
12
- };
13
- }
14
- getEmptyValue() {
15
- return [];
16
- }
17
- }
18
- //# sourceMappingURL=structured-array.js.map