proto.io 0.0.140 → 0.0.141

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,30 @@ const validateShapedObject = (schema, dataType) => {
692
692
  }
693
693
  }
694
694
  };
695
- const validateSchema = (schema) => {
695
+ const validateSchemaPermission = (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
+ const fields = _.keys(_schema.fields);
704
+ for (const key of _.keys(_schema.fieldLevelPermissions)) {
705
+ if (!fields.includes(key))
706
+ throw Error(`Invalid field permission: ${key}`);
707
+ }
708
+ for (const key of _schema.secureFields ?? []) {
709
+ if (!fields.includes(key))
710
+ throw Error(`Invalid field permission: ${key}`);
711
+ }
712
+ }
713
+ };
714
+ const validateSchema = (schema) => {
698
715
  for (const [className, _schema] of _.toPairs(schema)) {
699
716
  if (!className.match(QueryValidator.patterns.name))
700
717
  throw Error(`Invalid class name: ${className}`);
701
718
  for (const [key, dataType] of _.toPairs(_schema.fields)) {
702
- if (_.includes(TObject.defaultKeys, key))
703
- throw Error(`Reserved field name: ${key}`);
704
719
  if (!key.match(QueryValidator.patterns.name))
705
720
  throw Error(`Invalid field name: ${key}`);
706
721
  if (isShape(dataType)) {
@@ -716,15 +731,6 @@ const validateSchema = (schema) => {
716
731
  validateForeignField(schema, key, dataType);
717
732
  }
718
733
  }
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}`);
727
- }
728
734
  }
729
735
  };
730
736
  const mergeSchema = (...schemas) => _.reduce(schemas, (acc, schema) => ({
@@ -756,10 +762,12 @@ class ProtoInternal {
756
762
  functions = {};
757
763
  triggers = {};
758
764
  constructor(options) {
759
- validateSchema(options.schema);
765
+ validateSchemaPermission(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() {