@envelop/core 2.3.2-alpha-a0c2439.0 → 2.3.2-alpha-e4ba153.0
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/index.js +40 -23
- package/index.mjs +40 -23
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -1092,6 +1092,7 @@ const useSchema = (schema) => {
|
|
|
1092
1092
|
};
|
|
1093
1093
|
};
|
|
1094
1094
|
const VALIDATE_FN = Symbol('VALIDATE_FN');
|
|
1095
|
+
const VALIDATION_ERRORS = Symbol('VALIDATION_ERRORS');
|
|
1095
1096
|
const useLazyLoadedSchema = (schemaLoader, validateSchema = true) => {
|
|
1096
1097
|
let schemaSet$;
|
|
1097
1098
|
return {
|
|
@@ -1100,36 +1101,42 @@ const useLazyLoadedSchema = (schemaLoader, validateSchema = true) => {
|
|
|
1100
1101
|
if (isPromise(schema$)) {
|
|
1101
1102
|
schemaSet$ = schema$.then(schemaObj => {
|
|
1102
1103
|
setSchema(schemaObj);
|
|
1104
|
+
schemaSet$ = undefined;
|
|
1103
1105
|
});
|
|
1104
1106
|
}
|
|
1105
1107
|
else {
|
|
1106
1108
|
setSchema(schema$);
|
|
1107
1109
|
}
|
|
1108
1110
|
},
|
|
1109
|
-
onValidate({ validateFn, setValidationFn, extendContext }) {
|
|
1111
|
+
onValidate({ validateFn, params, setValidationFn, extendContext }) {
|
|
1110
1112
|
if (schemaSet$) {
|
|
1111
1113
|
if (validateSchema) {
|
|
1112
1114
|
extendContext({
|
|
1113
|
-
[VALIDATE_FN]: validateFn,
|
|
1115
|
+
[VALIDATE_FN]: (schema) => validateFn(schema, params.documentAST, params.rules, params.typeInfo, params.options),
|
|
1114
1116
|
});
|
|
1115
1117
|
}
|
|
1116
1118
|
setValidationFn(() => []);
|
|
1117
1119
|
}
|
|
1118
1120
|
},
|
|
1119
|
-
|
|
1120
|
-
if (
|
|
1121
|
-
const
|
|
1122
|
-
const
|
|
1121
|
+
async onContextBuilding({ context, extendContext, breakContextBuilding }) {
|
|
1122
|
+
if (context[VALIDATE_FN]) {
|
|
1123
|
+
const schema = await schemaSet$;
|
|
1124
|
+
const validateFn = context[VALIDATE_FN];
|
|
1125
|
+
const errors = validateFn === null || validateFn === void 0 ? void 0 : validateFn(schema);
|
|
1123
1126
|
if (errors === null || errors === void 0 ? void 0 : errors.length) {
|
|
1124
|
-
|
|
1125
|
-
errors,
|
|
1127
|
+
extendContext({
|
|
1128
|
+
[VALIDATION_ERRORS]: errors,
|
|
1126
1129
|
});
|
|
1127
|
-
|
|
1128
|
-
else {
|
|
1129
|
-
return schemaSet$;
|
|
1130
|
+
breakContextBuilding();
|
|
1130
1131
|
}
|
|
1131
1132
|
}
|
|
1132
|
-
|
|
1133
|
+
},
|
|
1134
|
+
onExecute({ args: { contextValue }, setResultAndStopExecution }) {
|
|
1135
|
+
if (contextValue[VALIDATION_ERRORS]) {
|
|
1136
|
+
setResultAndStopExecution({
|
|
1137
|
+
errors: contextValue[VALIDATION_ERRORS],
|
|
1138
|
+
});
|
|
1139
|
+
}
|
|
1133
1140
|
},
|
|
1134
1141
|
};
|
|
1135
1142
|
};
|
|
@@ -1140,36 +1147,46 @@ const useAsyncSchema = (schema$, validateSchema = true) => {
|
|
|
1140
1147
|
if (isPromise(schema$)) {
|
|
1141
1148
|
schemaSet$ = schema$.then(schemaObj => {
|
|
1142
1149
|
setSchema(schemaObj);
|
|
1150
|
+
// Once the schema is completely resolved, we don't need to keep the logic below.
|
|
1151
|
+
schemaSet$ = undefined;
|
|
1143
1152
|
});
|
|
1144
1153
|
}
|
|
1145
1154
|
else {
|
|
1146
1155
|
setSchema(schema$);
|
|
1147
1156
|
}
|
|
1148
1157
|
},
|
|
1149
|
-
onValidate({ validateFn, setValidationFn, extendContext }) {
|
|
1158
|
+
onValidate({ validateFn, params, setValidationFn, extendContext }) {
|
|
1159
|
+
// If schemaSet promise is still ongoing
|
|
1150
1160
|
if (schemaSet$) {
|
|
1151
1161
|
if (validateSchema) {
|
|
1152
1162
|
extendContext({
|
|
1153
|
-
[VALIDATE_FN]: validateFn,
|
|
1163
|
+
[VALIDATE_FN]: (schema) => validateFn(schema, params.documentAST, params.rules, params.typeInfo, params.options),
|
|
1154
1164
|
});
|
|
1155
1165
|
}
|
|
1156
1166
|
setValidationFn(() => []);
|
|
1157
1167
|
}
|
|
1158
1168
|
},
|
|
1159
|
-
|
|
1169
|
+
async onContextBuilding({ context, extendContext, breakContextBuilding }) {
|
|
1170
|
+
// If schemaSet promise is still ongoing
|
|
1160
1171
|
if (schemaSet$) {
|
|
1161
|
-
const
|
|
1162
|
-
const
|
|
1172
|
+
const schema = await schemaSet$;
|
|
1173
|
+
const validateFn = context[VALIDATE_FN];
|
|
1174
|
+
const errors = validateFn === null || validateFn === void 0 ? void 0 : validateFn(schema);
|
|
1163
1175
|
if (errors === null || errors === void 0 ? void 0 : errors.length) {
|
|
1164
|
-
|
|
1165
|
-
errors,
|
|
1176
|
+
extendContext({
|
|
1177
|
+
[VALIDATION_ERRORS]: errors,
|
|
1166
1178
|
});
|
|
1167
|
-
|
|
1168
|
-
else {
|
|
1169
|
-
return schemaSet$;
|
|
1179
|
+
breakContextBuilding();
|
|
1170
1180
|
}
|
|
1171
1181
|
}
|
|
1172
|
-
|
|
1182
|
+
},
|
|
1183
|
+
onExecute({ args: { contextValue }, setResultAndStopExecution }) {
|
|
1184
|
+
// If validation errors are set in context
|
|
1185
|
+
if (contextValue[VALIDATION_ERRORS]) {
|
|
1186
|
+
setResultAndStopExecution({
|
|
1187
|
+
errors: contextValue[VALIDATION_ERRORS],
|
|
1188
|
+
});
|
|
1189
|
+
}
|
|
1173
1190
|
},
|
|
1174
1191
|
};
|
|
1175
1192
|
};
|
package/index.mjs
CHANGED
|
@@ -1088,6 +1088,7 @@ const useSchema = (schema) => {
|
|
|
1088
1088
|
};
|
|
1089
1089
|
};
|
|
1090
1090
|
const VALIDATE_FN = Symbol('VALIDATE_FN');
|
|
1091
|
+
const VALIDATION_ERRORS = Symbol('VALIDATION_ERRORS');
|
|
1091
1092
|
const useLazyLoadedSchema = (schemaLoader, validateSchema = true) => {
|
|
1092
1093
|
let schemaSet$;
|
|
1093
1094
|
return {
|
|
@@ -1096,36 +1097,42 @@ const useLazyLoadedSchema = (schemaLoader, validateSchema = true) => {
|
|
|
1096
1097
|
if (isPromise(schema$)) {
|
|
1097
1098
|
schemaSet$ = schema$.then(schemaObj => {
|
|
1098
1099
|
setSchema(schemaObj);
|
|
1100
|
+
schemaSet$ = undefined;
|
|
1099
1101
|
});
|
|
1100
1102
|
}
|
|
1101
1103
|
else {
|
|
1102
1104
|
setSchema(schema$);
|
|
1103
1105
|
}
|
|
1104
1106
|
},
|
|
1105
|
-
onValidate({ validateFn, setValidationFn, extendContext }) {
|
|
1107
|
+
onValidate({ validateFn, params, setValidationFn, extendContext }) {
|
|
1106
1108
|
if (schemaSet$) {
|
|
1107
1109
|
if (validateSchema) {
|
|
1108
1110
|
extendContext({
|
|
1109
|
-
[VALIDATE_FN]: validateFn,
|
|
1111
|
+
[VALIDATE_FN]: (schema) => validateFn(schema, params.documentAST, params.rules, params.typeInfo, params.options),
|
|
1110
1112
|
});
|
|
1111
1113
|
}
|
|
1112
1114
|
setValidationFn(() => []);
|
|
1113
1115
|
}
|
|
1114
1116
|
},
|
|
1115
|
-
|
|
1116
|
-
if (
|
|
1117
|
-
const
|
|
1118
|
-
const
|
|
1117
|
+
async onContextBuilding({ context, extendContext, breakContextBuilding }) {
|
|
1118
|
+
if (context[VALIDATE_FN]) {
|
|
1119
|
+
const schema = await schemaSet$;
|
|
1120
|
+
const validateFn = context[VALIDATE_FN];
|
|
1121
|
+
const errors = validateFn === null || validateFn === void 0 ? void 0 : validateFn(schema);
|
|
1119
1122
|
if (errors === null || errors === void 0 ? void 0 : errors.length) {
|
|
1120
|
-
|
|
1121
|
-
errors,
|
|
1123
|
+
extendContext({
|
|
1124
|
+
[VALIDATION_ERRORS]: errors,
|
|
1122
1125
|
});
|
|
1123
|
-
|
|
1124
|
-
else {
|
|
1125
|
-
return schemaSet$;
|
|
1126
|
+
breakContextBuilding();
|
|
1126
1127
|
}
|
|
1127
1128
|
}
|
|
1128
|
-
|
|
1129
|
+
},
|
|
1130
|
+
onExecute({ args: { contextValue }, setResultAndStopExecution }) {
|
|
1131
|
+
if (contextValue[VALIDATION_ERRORS]) {
|
|
1132
|
+
setResultAndStopExecution({
|
|
1133
|
+
errors: contextValue[VALIDATION_ERRORS],
|
|
1134
|
+
});
|
|
1135
|
+
}
|
|
1129
1136
|
},
|
|
1130
1137
|
};
|
|
1131
1138
|
};
|
|
@@ -1136,36 +1143,46 @@ const useAsyncSchema = (schema$, validateSchema = true) => {
|
|
|
1136
1143
|
if (isPromise(schema$)) {
|
|
1137
1144
|
schemaSet$ = schema$.then(schemaObj => {
|
|
1138
1145
|
setSchema(schemaObj);
|
|
1146
|
+
// Once the schema is completely resolved, we don't need to keep the logic below.
|
|
1147
|
+
schemaSet$ = undefined;
|
|
1139
1148
|
});
|
|
1140
1149
|
}
|
|
1141
1150
|
else {
|
|
1142
1151
|
setSchema(schema$);
|
|
1143
1152
|
}
|
|
1144
1153
|
},
|
|
1145
|
-
onValidate({ validateFn, setValidationFn, extendContext }) {
|
|
1154
|
+
onValidate({ validateFn, params, setValidationFn, extendContext }) {
|
|
1155
|
+
// If schemaSet promise is still ongoing
|
|
1146
1156
|
if (schemaSet$) {
|
|
1147
1157
|
if (validateSchema) {
|
|
1148
1158
|
extendContext({
|
|
1149
|
-
[VALIDATE_FN]: validateFn,
|
|
1159
|
+
[VALIDATE_FN]: (schema) => validateFn(schema, params.documentAST, params.rules, params.typeInfo, params.options),
|
|
1150
1160
|
});
|
|
1151
1161
|
}
|
|
1152
1162
|
setValidationFn(() => []);
|
|
1153
1163
|
}
|
|
1154
1164
|
},
|
|
1155
|
-
|
|
1165
|
+
async onContextBuilding({ context, extendContext, breakContextBuilding }) {
|
|
1166
|
+
// If schemaSet promise is still ongoing
|
|
1156
1167
|
if (schemaSet$) {
|
|
1157
|
-
const
|
|
1158
|
-
const
|
|
1168
|
+
const schema = await schemaSet$;
|
|
1169
|
+
const validateFn = context[VALIDATE_FN];
|
|
1170
|
+
const errors = validateFn === null || validateFn === void 0 ? void 0 : validateFn(schema);
|
|
1159
1171
|
if (errors === null || errors === void 0 ? void 0 : errors.length) {
|
|
1160
|
-
|
|
1161
|
-
errors,
|
|
1172
|
+
extendContext({
|
|
1173
|
+
[VALIDATION_ERRORS]: errors,
|
|
1162
1174
|
});
|
|
1163
|
-
|
|
1164
|
-
else {
|
|
1165
|
-
return schemaSet$;
|
|
1175
|
+
breakContextBuilding();
|
|
1166
1176
|
}
|
|
1167
1177
|
}
|
|
1168
|
-
|
|
1178
|
+
},
|
|
1179
|
+
onExecute({ args: { contextValue }, setResultAndStopExecution }) {
|
|
1180
|
+
// If validation errors are set in context
|
|
1181
|
+
if (contextValue[VALIDATION_ERRORS]) {
|
|
1182
|
+
setResultAndStopExecution({
|
|
1183
|
+
errors: contextValue[VALIDATION_ERRORS],
|
|
1184
|
+
});
|
|
1185
|
+
}
|
|
1169
1186
|
},
|
|
1170
1187
|
};
|
|
1171
1188
|
};
|