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