proto.io 0.0.140 → 0.0.142

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.
package/dist/index.mjs CHANGED
@@ -692,15 +692,21 @@ const validateShapedObject = (schema, dataType) => {
692
692
  }
693
693
  }
694
694
  };
695
- const validateSchema = (schema) => {
695
+ const validateSchemaName = (schema) => {
696
696
  if (!_.isNil(schema['_Schema']) || !_.isNil(schema['_Config']))
697
697
  throw Error('Reserved name of class');
698
+ for (const [, _schema] of _.toPairs(schema)) {
699
+ for (const [key] of _.toPairs(_schema.fields)) {
700
+ if (_.includes(TObject.defaultKeys, key))
701
+ throw Error(`Reserved field name: ${key}`);
702
+ }
703
+ }
704
+ };
705
+ const validateSchema = (schema) => {
698
706
  for (const [className, _schema] of _.toPairs(schema)) {
699
707
  if (!className.match(QueryValidator.patterns.name))
700
708
  throw Error(`Invalid class name: ${className}`);
701
709
  for (const [key, dataType] of _.toPairs(_schema.fields)) {
702
- if (_.includes(TObject.defaultKeys, key))
703
- throw Error(`Reserved field name: ${key}`);
704
710
  if (!key.match(QueryValidator.patterns.name))
705
711
  throw Error(`Invalid field name: ${key}`);
706
712
  if (isShape(dataType)) {
@@ -715,15 +721,15 @@ const validateSchema = (schema) => {
715
721
  throw Error(`Invalid target: ${key}`);
716
722
  validateForeignField(schema, key, dataType);
717
723
  }
718
- }
719
- const fields = _.keys(_schema.fields);
720
- for (const key of _.keys(_schema.fieldLevelPermissions)) {
721
- if (!fields.includes(key))
722
- throw Error(`Invalid field permission: ${key}`);
723
- }
724
- for (const key of _schema.secureFields ?? []) {
725
- if (!fields.includes(key))
726
- throw Error(`Invalid field permission: ${key}`);
724
+ const fields = _.keys(_schema.fields);
725
+ for (const key of _.keys(_schema.fieldLevelPermissions)) {
726
+ if (!fields.includes(key))
727
+ throw Error(`Invalid field permission: ${key}`);
728
+ }
729
+ for (const key of _schema.secureFields ?? []) {
730
+ if (!fields.includes(key))
731
+ throw Error(`Invalid field permission: ${key}`);
732
+ }
727
733
  }
728
734
  }
729
735
  };
@@ -756,10 +762,12 @@ class ProtoInternal {
756
762
  functions = {};
757
763
  triggers = {};
758
764
  constructor(options) {
759
- validateSchema(options.schema);
765
+ validateSchemaName(options.schema);
766
+ const schema = mergeSchema(defaultSchema, options.fileStorage.schema, options.schema);
767
+ validateSchema(schema);
760
768
  this.options = {
761
769
  ...options,
762
- schema: mergeSchema(defaultSchema, options.fileStorage.schema, options.schema),
770
+ schema,
763
771
  };
764
772
  }
765
773
  async prepare() {