forms-angular 0.12.0-beta.244 → 0.12.0-beta.245

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.
@@ -220,7 +220,7 @@ class FormsAngular {
220
220
  }
221
221
  }
222
222
  }
223
- extend(resource.options, this.preprocess(resource, resource.model.schema['paths'], null));
223
+ extend(resource.options, this.preprocess(resource, resource.model.schema['paths']));
224
224
  if (resource.options.searchImportance) {
225
225
  this.searchFunc = async.forEachSeries;
226
226
  }
@@ -695,70 +695,100 @@ class FormsAngular {
695
695
  return outPath;
696
696
  }
697
697
  ;
698
- preprocess(resource, paths, formSchema) {
699
- let outPath = {}, hiddenFields = [], listFields = [];
700
- if (resource && resource.options && resource.options.idIsList) {
701
- paths['_id'].options = paths['_id'].options || {};
702
- paths['_id'].options.list = resource.options.idIsList;
703
- }
704
- for (let element in paths) {
705
- if (paths.hasOwnProperty(element) && element !== '__v') {
706
- // check for schemas
707
- if (paths[element].schema) {
708
- let subSchemaInfo = this.preprocess(null, paths[element].schema.paths);
709
- outPath[element] = { schema: subSchemaInfo.paths };
710
- if (paths[element].options.form) {
711
- outPath[element].options = { form: extend(true, {}, paths[element].options.form) };
712
- }
713
- // this provides support for entire nested schemas that wish to remain hidden
714
- if (paths[element].options.secure) {
715
- hiddenFields.push(element);
716
- }
717
- // to support hiding individual properties of nested schema would require us
718
- // to do something with subSchemaInfo.hide here
719
- }
720
- else {
721
- // check for arrays
722
- let realType = paths[element].caster ? paths[element].caster : paths[element];
723
- if (!realType.instance) {
724
- if (realType.options.type) {
725
- let type = realType.options.type(), typeType = typeof type;
726
- if (typeType === 'string') {
727
- realType.instance = (!isNaN(Date.parse(type))) ? 'Date' : 'String';
728
- }
729
- else {
730
- realType.instance = typeType;
698
+ preprocess(resource, paths, formName, formSchema) {
699
+ function processInternalObject(obj) {
700
+ return Object.keys(obj).reduce((acc, cur) => {
701
+ const curType = typeof obj[cur];
702
+ if (!['$', '_'].includes(cur.charAt(0)) && curType !== 'function') {
703
+ const val = obj[cur];
704
+ if (val) {
705
+ if (Array.isArray(val)) {
706
+ if (val.length > 0) {
707
+ acc[cur] = val;
731
708
  }
732
709
  }
710
+ else if (curType === 'object') {
711
+ acc[cur] = processInternalObject(obj[cur]);
712
+ }
713
+ else {
714
+ acc[cur] = obj[cur];
715
+ }
733
716
  }
734
- outPath[element] = extend(true, {}, paths[element]);
735
- delete outPath[element].$parentSchemaDocArray; // This is a circular reference and can't be stringified
736
- if (paths[element].options.secure) {
737
- hiddenFields.push(element);
738
- }
739
- if (paths[element].options.match) {
740
- outPath[element].options.match = paths[element].options.match.source || paths[element].options.match;
717
+ }
718
+ return acc;
719
+ }, {});
720
+ }
721
+ let outPath = {}, hiddenFields = [], listFields = [];
722
+ if (resource && resource.preprocessed && resource.preprocessed[formName || "__default"]) {
723
+ return resource.preprocessed[formName || "__default"].paths;
724
+ }
725
+ else {
726
+ if (resource && resource.options && resource.options.idIsList) {
727
+ paths['_id'].options = paths['_id'].options || {};
728
+ paths['_id'].options.list = resource.options.idIsList;
729
+ }
730
+ for (let element in paths) {
731
+ if (paths.hasOwnProperty(element) && element !== '__v') {
732
+ // check for schemas
733
+ if (paths[element].schema) {
734
+ let subSchemaInfo = this.preprocess(null, paths[element].schema.paths);
735
+ outPath[element] = { schema: subSchemaInfo.paths };
736
+ if (paths[element].options.form) {
737
+ outPath[element].options = { form: extend(true, {}, paths[element].options.form) };
738
+ }
739
+ // this provides support for entire nested schemas that wish to remain hidden
740
+ if (paths[element].options.secure) {
741
+ hiddenFields.push(element);
742
+ }
743
+ // to support hiding individual properties of nested schema would require us
744
+ // to do something with subSchemaInfo.hide here
741
745
  }
742
- let schemaListInfo = paths[element].options.list;
743
- if (schemaListInfo) {
744
- let listFieldInfo = { field: element };
745
- if (typeof schemaListInfo === 'object' && Object.keys(schemaListInfo).length > 0) {
746
- listFieldInfo.params = schemaListInfo;
746
+ else {
747
+ // check for arrays
748
+ let realType = paths[element].caster ? paths[element].caster : paths[element];
749
+ if (!realType.instance) {
750
+ if (realType.options.type) {
751
+ let type = realType.options.type(), typeType = typeof type;
752
+ if (typeType === 'string') {
753
+ realType.instance = (!isNaN(Date.parse(type))) ? 'Date' : 'String';
754
+ }
755
+ else {
756
+ realType.instance = typeType;
757
+ }
758
+ }
759
+ }
760
+ outPath[element] = processInternalObject(paths[element]);
761
+ if (paths[element].options.secure) {
762
+ hiddenFields.push(element);
763
+ }
764
+ if (paths[element].options.match) {
765
+ outPath[element].options.match = paths[element].options.match.source || paths[element].options.match;
766
+ }
767
+ let schemaListInfo = paths[element].options.list;
768
+ if (schemaListInfo) {
769
+ let listFieldInfo = { field: element };
770
+ if (typeof schemaListInfo === 'object' && Object.keys(schemaListInfo).length > 0) {
771
+ listFieldInfo.params = schemaListInfo;
772
+ }
773
+ listFields.push(listFieldInfo);
747
774
  }
748
- listFields.push(listFieldInfo);
749
775
  }
750
776
  }
751
777
  }
778
+ outPath = this.applySchemaSubset(outPath, formSchema);
779
+ let returnObj = { paths: outPath };
780
+ if (hiddenFields.length > 0) {
781
+ returnObj.hide = hiddenFields;
782
+ }
783
+ if (listFields.length > 0) {
784
+ returnObj.listFields = listFields;
785
+ }
786
+ if (resource) {
787
+ resource.preprocessed = resource.preprocessed || {};
788
+ resource.preprocessed[formName || "__default"] = returnObj;
789
+ }
790
+ return returnObj;
752
791
  }
753
- outPath = this.applySchemaSubset(outPath, formSchema);
754
- let returnObj = { paths: outPath };
755
- if (hiddenFields.length > 0) {
756
- returnObj.hide = hiddenFields;
757
- }
758
- if (listFields.length > 0) {
759
- returnObj.listFields = listFields;
760
- }
761
- return returnObj;
762
792
  }
763
793
  ;
764
794
  schema() {
@@ -767,16 +797,22 @@ class FormsAngular {
767
797
  return res.status(404).end();
768
798
  }
769
799
  let formSchema = null;
770
- if (req.params.formName) {
771
- try {
772
- formSchema = req.resource.model.schema.statics['form'](req.params.formName, req);
773
- }
774
- catch (e) {
775
- return res.status(500).send(e.message);
800
+ const formName = req.params.formName;
801
+ if (req.resource.preprocessed?.[formName || "__default"]) {
802
+ res.send(req.resource.preprocessed[formName || "__default"].paths);
803
+ }
804
+ else {
805
+ if (formName) {
806
+ try {
807
+ formSchema = req.resource.model.schema.statics['form'](formName, req);
808
+ }
809
+ catch (e) {
810
+ return res.status(500).send(e.message);
811
+ }
776
812
  }
813
+ let paths = this.preprocess(req.resource, req.resource.model.schema.paths, formName, formSchema).paths;
814
+ res.send(paths);
777
815
  }
778
- let paths = this.preprocess(req.resource, req.resource.model.schema.paths, formSchema).paths;
779
- res.send(paths);
780
816
  }, this);
781
817
  }
782
818
  ;
@@ -93,6 +93,7 @@ declare module fngServer {
93
93
  interface Resource extends ResourceExport {
94
94
  resourceName: string;
95
95
  resourceNameLower: string;
96
+ preprocessed?: {[formName: string] : any};
96
97
  }
97
98
 
98
99
  interface ListParams {
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "author": "Mark Chapman <support@forms-angular.org>",
4
4
  "description": "A form builder that sits on top of Angular.js, Twitter Bootstrap, jQuery UI, Angular-UI, Express and Mongoose. Opinionated or what?",
5
5
  "homepage": "http://forms-angular.org",
6
- "version": "0.12.0-beta.244",
6
+ "version": "0.12.0-beta.245",
7
7
  "engines": {
8
8
  "node": ">=8.x",
9
9
  "npm": ">=5.x"
@@ -54,7 +54,7 @@
54
54
  },
55
55
  "peerDependencies": {
56
56
  "express": "^4",
57
- "mongoose": "^8"
57
+ "mongoose": "^7.3.3 || ^8"
58
58
  },
59
59
  "devDependencies": {
60
60
  "@types/angular": "1.8.9",