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