@sealcode/sealgen 0.19.11 → 0.19.13

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.
@@ -1,5 +1,10 @@
1
+ import { ExtractedFieldInfo } from "../../utils/extract-fields-from-collection.js";
1
2
  import { TextBasedSimpleField } from "./simple-form-field.js";
2
3
  export declare class Password<Required extends boolean> extends TextBasedSimpleField<Required> {
3
4
  constructor(required: Required);
4
5
  sealiousValueToForm(): Promise<undefined>;
6
+ generateInitialValue(field_info: ExtractedFieldInfo, vars: {
7
+ form_field_types: string;
8
+ form_fields: string;
9
+ }): string;
5
10
  }
@@ -6,11 +6,7 @@ export type ExtractedFieldInfo = {
6
6
  referencing_collection: string | null;
7
7
  referencing_field: string | null;
8
8
  intermediary_field_that_points_there: string | null;
9
- is_readonly: boolean;
10
9
  is_required: boolean;
11
- subfields: {
12
- name: string;
13
- }[];
14
10
  };
15
11
  export type ExtractedFieldInfoWithFormField = ExtractedFieldInfo & {
16
12
  form_field: FormField;
@@ -1,3 +1,4 @@
1
+ import { wrapAttribute, wrapKeyName } from "../../utils/wrap-attributes.js";
1
2
  import { TextBasedSimpleField } from "./simple-form-field.js";
2
3
  class Password extends TextBasedSimpleField {
3
4
  constructor(required) {
@@ -6,6 +7,9 @@ class Password extends TextBasedSimpleField {
6
7
  async sealiousValueToForm() {
7
8
  return void 0;
8
9
  }
10
+ generateInitialValue(field_info, vars) {
11
+ return `${wrapKeyName(field_info.name)}: await ${vars.form_fields}${wrapAttribute(field_info.name)}.sealiousValueToForm()`;
12
+ }
9
13
  }
10
14
  export {
11
15
  Password
@@ -26,11 +26,11 @@ class MountableWithFields extends Mountable {
26
26
  } else if (!this.fields) {
27
27
  throw new Error("Fields not defined and getter not provided");
28
28
  }
29
- this.controls = this.getControls(this.fields);
30
29
  for (const [field_name, field] of Object.entries(this.fields)) {
31
30
  void field.init();
32
31
  field.setName(field_name);
33
32
  }
33
+ this.controls = this.getControls(this.fields);
34
34
  this.initialized = true;
35
35
  }
36
36
  makeFormControlContext(ctx, data, validate, field_name_prefix = this.field_names_prefix, form_id = this.form_id) {
@@ -25,14 +25,10 @@ for (const field_name in c.fields){
25
25
  let referencing_collection = null;
26
26
  let referencing_field = null;
27
27
  let intermediary_field_that_points_there = null;
28
- let is_readonly = false;
29
28
  let is_required = field.required || false;
30
- let subfields = [];
31
29
  if(["derived-value", "cached-value", "settable-by", "control-access"].includes(type)){
32
30
  type = field.virtual_field.typeName;
33
- }
34
- if(["derived-value", "cached-value", "reverse-single-reference"].includes(field.typeName)){
35
- is_readonly = true;
31
+ field = field.virtual_field
36
32
  }
37
33
  if(type == "single-reference"){
38
34
  target = field.target_collection;
@@ -46,10 +42,7 @@ for (const field_name in c.fields){
46
42
  referencing_field = field.referencing_field;
47
43
  intermediary_field_that_points_there = field.intermediary_field_that_points_there
48
44
  }
49
- if( type == "structured-array" ) {
50
- subfields = Object.keys(field.subfields || field.virtual_field.subfields).map(key=>({name: key}));
51
- }
52
- fields.push({ name: field_name, type, target, referencing_collection, referencing_field, intermediary_field_that_points_there, is_readonly, is_required, subfields })
45
+ fields.push({ name: field_name, type, target, referencing_collection, referencing_field, intermediary_field_that_points_there, is_required })
53
46
  }
54
47
  console.log(JSON.stringify(fields));
55
48
  `;
@@ -66,7 +59,6 @@ for (const field_name in c.fields){
66
59
  predicates.shape({
67
60
  name: predicates.string,
68
61
  type: predicates.string,
69
- is_readonly: predicates.boolean,
70
62
  target: predicates.or(
71
63
  predicates.string,
72
64
  predicates.null
@@ -83,9 +75,6 @@ for (const field_name in c.fields){
83
75
  intermediary_field_that_points_there: predicates.or(
84
76
  predicates.string,
85
77
  predicates.null
86
- ),
87
- subfields: predicates.array(
88
- predicates.shape({ name: predicates.string })
89
78
  )
90
79
  })
91
80
  )
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sealcode/sealgen",
3
- "version": "0.19.11",
3
+ "version": "0.19.13",
4
4
  "description": "Module to automate adding routes and collections to a sealious application",
5
5
  "main": "lib/index.js",
6
6
  "type": "module",
@@ -92,7 +92,7 @@
92
92
  "peerDependencies": {
93
93
  "koa": "^2.13.0",
94
94
  "koa-responsive-image-router": "^0.2.24",
95
- "sealious": "^0.21.20",
95
+ "sealious": "^0.21.29",
96
96
  "stimulus": "^3.2.2"
97
97
  }
98
98
  }
@@ -1,3 +1,5 @@
1
+ import { ExtractedFieldInfo } from "../../utils/extract-fields-from-collection.js";
2
+ import { wrapAttribute, wrapKeyName } from "../../utils/wrap-attributes.js";
1
3
  import { TextBasedSimpleField } from "./simple-form-field.js";
2
4
 
3
5
  export class Password<
@@ -10,4 +12,16 @@ export class Password<
10
12
  async sealiousValueToForm(): Promise<undefined> {
11
13
  return undefined;
12
14
  }
15
+
16
+ generateInitialValue(
17
+ field_info: ExtractedFieldInfo,
18
+ vars: {
19
+ form_field_types: string;
20
+ form_fields: string;
21
+ }
22
+ ): string {
23
+ return `${wrapKeyName(field_info.name)}: await ${
24
+ vars.form_fields
25
+ }${wrapAttribute(field_info.name)}.sealiousValueToForm()`;
26
+ }
13
27
  }
@@ -57,11 +57,11 @@ export abstract class MountableWithFields<
57
57
  } else if (!this.fields) {
58
58
  throw new Error("Fields not defined and getter not provided");
59
59
  }
60
- this.controls = this.getControls(this.fields);
61
60
  for (const [field_name, field] of Object.entries(this.fields)) {
62
61
  void field.init();
63
62
  field.setName(field_name);
64
63
  }
64
+ this.controls = this.getControls(this.fields);
65
65
  this.initialized = true;
66
66
  }
67
67
 
@@ -13,9 +13,7 @@ export type ExtractedFieldInfo = {
13
13
  referencing_collection: string | null;
14
14
  referencing_field: string | null;
15
15
  intermediary_field_that_points_there: string | null;
16
- is_readonly: boolean;
17
16
  is_required: boolean;
18
- subfields: { name: string }[];
19
17
  };
20
18
 
21
19
  export type ExtractedFieldInfoWithFormField = ExtractedFieldInfo & {
@@ -50,14 +48,10 @@ for (const field_name in c.fields){
50
48
  let referencing_collection = null;
51
49
  let referencing_field = null;
52
50
  let intermediary_field_that_points_there = null;
53
- let is_readonly = false;
54
51
  let is_required = field.required || false;
55
- let subfields = [];
56
52
  if(["derived-value", "cached-value", "settable-by", "control-access"].includes(type)){
57
53
  type = field.virtual_field.typeName;
58
- }
59
- if(["derived-value", "cached-value", "reverse-single-reference"].includes(field.typeName)){
60
- is_readonly = true;
54
+ field = field.virtual_field
61
55
  }
62
56
  if(type == "single-reference"){
63
57
  target = field.target_collection;
@@ -71,10 +65,7 @@ for (const field_name in c.fields){
71
65
  referencing_field = field.referencing_field;
72
66
  intermediary_field_that_points_there = field.intermediary_field_that_points_there
73
67
  }
74
- if( type == "structured-array" ) {
75
- subfields = Object.keys(field.subfields || field.virtual_field.subfields).map(key=>({name: key}));
76
- }
77
- fields.push({ name: field_name, type, target, referencing_collection, referencing_field, intermediary_field_that_points_there, is_readonly, is_required, subfields })
68
+ fields.push({ name: field_name, type, target, referencing_collection, referencing_field, intermediary_field_that_points_there, is_required })
78
69
  }
79
70
  console.log(JSON.stringify(fields));
80
71
  `;
@@ -93,7 +84,6 @@ for (const field_name in c.fields){
93
84
  predicates.shape({
94
85
  name: predicates.string,
95
86
  type: predicates.string,
96
- is_readonly: predicates.boolean,
97
87
  target: predicates.or(
98
88
  predicates.string,
99
89
  predicates.null
@@ -111,9 +101,6 @@ for (const field_name in c.fields){
111
101
  predicates.string,
112
102
  predicates.null
113
103
  ),
114
- subfields: predicates.array(
115
- predicates.shape({ name: predicates.string })
116
- ),
117
104
  })
118
105
  )
119
106
  )